Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RouteName:
- pattern: /some/route
- defaults: { _controller: MyAppBundle:Controller:action }
- $this->get('router')->generate('RouteName');
- namespace MyAppBundleView;
- class ViewClass {
- public function uri()
- {
- return getTheRoute('RouteName');
- }
- }
- viewclass.service:
- class: NamespaceForViewClass
- arguments:
- router: "@router"
- public function __construct(SymfonyBundleFrameworkBundleRoutingRouter $router)
- {
- $this->router = $router;
- }
- /**
- * Generates a URL from the given parameters.
- *
- * @param string $route The name of the route
- * @param mixed $parameters An array of parameters
- * @param Boolean $absolute Whether to generate an absolute URL
- *
- * @return string The generated URL
- */
- public function generateUrl($route, $parameters = array(), $absolute = false)
- {
- return $this->container->get('router')->generate($route, $parameters, $absolute);
- }
- class View
- {
- protected $container;
- public function __construct(SymfonyComponentDependencyInjectionContainer $container)
- {
- $this->container = $container;
- }
- }
- $this->container->get('router')->generate($route, $parameters, $absolute);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement