1

How can I use the url() controller helper inside the console?

I have to generate some urls using an action of the console, but if I call $this->controller->url()->fromRoute(...);, I can only ask for routes defined in the console router.

In other words, I need the ability to call all the routes of the application's main router.

Thanks

1 Answer 1

1

I'm not sure, that it is a good decision, but you can change router manually:

// ConsoleController.php

// Change router to HTTP    
$this->getEvent()->setRouter($this->getServiceLocator()->get('HttpRouter'));

// Get any HTTP route
var_dump($this->url()->fromRoute('your_http_route'));

// Change it back, if you want
$this->getEvent()->setRouter($this->getServiceLocator()->get('Router'));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.