Created
July 20, 2011 17:27
-
-
Save mattattui/1095423 to your computer and use it in GitHub Desktop.
Sample Object Route Extension
This file contains hidden or 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
services: | |
JobRoute.twig.extension: | |
class: Me\MyBundle\Extension\JobRouteExtension | |
arguments: [@router] | |
tags: | |
- { name: twig.extension } |
This file contains hidden or 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 Me\MyBundle\Extension; | |
use Me\MyBundle\Entity\Job; | |
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |
class JobRouteExtension extends \Twig_Extension | |
{ | |
private $generator; | |
public function __construct(UrlGeneratorInterface $generator) | |
{ | |
$this->generator = $generator; | |
} | |
public function getFunctions() { | |
return array( | |
'job_url' => new \Twig_Filter_Method($this, 'job_url'), | |
); | |
} | |
public function job_url(Job $job) | |
{ | |
$name = 'job_show'; | |
$parameters = array( | |
'company' => $job->getCompanySlug(), | |
'location' => $job->getLocationSlug(), | |
'id' => $job->getId(), | |
'position' => $job->getPositionSlug(), | |
) | |
return $this->generator->generate($name, $parameters, true); | |
} | |
public function getName() | |
{ | |
return 'job_route'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment