symfony - Create custom router service -


am creating own framework based on sf2 commponents , try create router service.

i need service generateurl() method

protected function generateurl($route, $parameters = array(), $referencetype = urlgeneratorinterface::absolute_path) {     return $this->get('router')->generate($route, $parameters, $referencetype); } 

i try this

$container = new containerbuilder();  $container->setdefinition('router_loader', new definition('symfony\component\config\loader\loaderinterface')); $container->setdefinition('router', new definition('symfony\component\routing\router', array())); 

and when execute in methodaction

$this->generateurl('home'); 

he return me:

catchable fatal error: argument 1 passed symfony\component\routing\router::__construct() must instance of symfony\component\config\loader\loaderinterface, none given in d:\xampp\htdocs\my_fw\vendor\symfony\routing\router.php on line 95

looking on router constructor see. need interface

   public function __construct(loaderinterface $loader, $resource, array $options = array(), requestcontext $context = null, loggerinterface $logger = null) 

how avoid implementation in service?

**new update:** routing.php  use symfony\component\routing\routecollection; use symfony\component\routing\route;  // routing $routes = new routecollection();  // home  $routes->add('home', new route('/', array(     '_controller' => 'mycompany\\controller\\homecontroller::indexaction', ))); 

you having error because configuring router service no service definition service definition should have service arguments source of error because container try create router no arguments check this

for better use can configure router service in service.yml/.xml file


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -