Created
July 30, 2013 13:15
-
-
Save h4cc/6112787 to your computer and use it in GitHub Desktop.
How to add a _url default to routes, so a external url can be generated by name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
router.options.generator_class: "Acme\\DemoBundle\\Routing\\Generator\\UrlGenerator" | |
router.options.generator_base_class: "Acme\\DemoBundle\\Routing\\Generator\\UrlGenerator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will generate a url to google. | |
to_google: | |
path: /to-google | |
defaults: | |
_url: "http://www.google.com/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Routing\Generator; | |
use Symfony\Component\Routing\Generator\UrlGenerator as BaseUrlGenerator; | |
class UrlGenerator extends BaseUrlGenerator | |
{ | |
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens) | |
{ | |
if(isset($defaults['_url'])) { | |
return $defaults['_url']; | |
} | |
return parent::doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why not use
host
andschemes
options instead? i.e: