ZF2 main router in console - zend-framework

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

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'));

Related

Flutter Navigator Observer get path of old and new route

I am trying to call an function, if the Router changes the first part of a Route. I do use a NavigatorObserver and know about the functions didPop/didPush.
I have the Routes like: "/page1", "/page2", "/page1/subpage1", "/page1/subpage2", "/page2/subpage1", "/page2/subpage1/subsubpage1".
When the the Router changes I want to know if I changed the page, regardless of the sub page.
The functions give the old and new route a Route objects. But I can't figure out how to check these for the bottom route. I only managed to access the name of the page and to check if the Route is a first in the path. but that doen't help.
Does someone here know how I could get the complete path from the Route object or how else I could get it?

Angular4 - Change state from component not template

In AngularJS I used ui-router for redirecting inside of my app(changing state).
It has 2 possible options to redirect
In template ui-sref='stateName'
In controller $state.go()
I just start play with Angular (4) and I found only way how to change route from template with something like:
Template routerLink="routePath"
Is there some way as there was in ui-router to change route from component?
constructor(private router:Router) {}
changeRoute() {
this.router.navigate(...)
// this.router.navigateByUrl(...)
}
See also https://angular.io/docs/ts/latest/api/router/index/Router-class.html
you can navigate via router like this
router.navigate([URL])
or like this
router.navigateByUrl('whole_string_containing_full_path')
Here router is an instance created in constructor, which is imported from router firstly, basically there is no difference between these two
First one accept array where as second one accept url in the form of string.

Play Framework 2.4 routing: one route for multiple urls Scala

I have admin part in my project which use React.js and React router.
And I need to render the same view on each request which starts with /admin in case user hit Refresh or come straight to url.
I don't need to pass any parameters to view. How can it be done?
You can define your route like this in play:
/admin/*url controllers.Application.admin(url)

Play 2.1.x default catch all route

Is there a default catch all fallback route in Play framework? If so how can I configure it in my routes file? Currently, there are some urls that I do not want the user to call them and even if they call, I don't want that error page appearing, rather I want them to go to the landing page of my web app! Is there a way to do that in the routes configuration file?
Simply define a route matching any path at the end of your routes file. Do not forget to define specific routes for your assets though, for example:
GET / controllers.Application.index
GET /some/path controllers.Application.someHandler
...
# End of file
GET /favicon.ico controllers.Assets.at(path="/public", file="img/favicon.ico")
GET /$file<(css|img|js|partials)/.*> controllers.Assets.at(path="/public", file)
GET /$path<.*> controllers.Application.catchall(path)
Any URL not matched by an earlier rule will be matched by this one.
Catch all routes makes sense when you want to do something with the path (ie. resolve it manually in your custom action), otherwise it's enough to use common onHandlerNotFound in your Global object and redirect request wherever you want.

An explanation of the Zend Redirector Action Helper

Is there a comprehensive explanation of how the Zend Redirector Action Helper works? I've read the reference guide, but am still not 100% clear. For example:
Apparently the goToSimple() is more like a forward(), than a redirect. Does this mean that it won't send a redirect message back to the browser?
If I want to send a redirect message back to the browser, which Redirector method should I be using?
Is there a way to get the forward() type of behaviour, without re-executing the init() method of Action Helpers?
This problem cropped up when I was implementing an ACL. I have an ACL Action Helper and its init() method adds the role 'current'. When I use the redirector's goToSimple() I get an error saying that the role is already registered. I can use if (!$acl->hasRole('current')) however I think it would be preferable not to be re-executing the helper's init() in the first place.
Not too comprehensive just a few quick notes about the redirector.
The redirector does a little bit more than a regular PHP redirect which you would use with header('Location: www.domain.com/new/location') in your script--following by an exit().
If you look at Zend_Controller_Action_Helper_Redirector it ultimately does exactly the same; if $_exit==true (default) everything leads to redirectAndExit() which calls header() and ends with an exit() call. However it terminates the framework properly, mainly the session if any.
The redirector does not forward internally it sends a default 302 code back unless you have set another code with setCode().
Methods gotoRoute() and gotoSimple() assemble the destination URL for you and call redirectAndExit() but only if $_exit==true. Or you can use their brethren gotoRouteAndExit() and gotoSimpleAndExit() which will exit immediately. The gotoSimple methods pass on to setGotoSimple which uses some methods to assemble the URL for you.
In your case I can only assume that the setGotoSimple method and one of the methods in it call the destination controller and fire up the init() method; however, only for checking but not forwarding.