php - Zend 2 equivalent of Laravel 4 Route Filter -


I am new in Zend 2, I first started with Laverail and I need to do what I know. Strong> Laravel root filter , but I'm using Zend 2.

I checked the document of Zend 2 and I do not think so.

I need to do some routes and goods only on the selected routes and I do not want to add that code to every function of every path because I have more than 50 different routes here, but in larval i Filter the filter using the route so that in the selected routes, it should be first in the filter before going on that path.

In the path of the larval:

  Root :: Mill ('route 1', array '(before' = 'gt;' normal ',' ') Is' = & gt; 'GenericController @ getIndex')); Route: received ('before' = & gt 'route2', array (; 'normal', 'uses' => 'genericcontroller @ getIndex')); Route :: filter ('normal', 'rootfilters');  

I have not used Laravel before, but I follow this link I am very afraid that,

No, it does not exist

You will use the controller:

 < Code> public functions some actions () {if (! Bet is true) {return $ this- & gt; NotFoundAction (); // or return $ this - & gt; Redirect () - & gt; ToRoute ('MyRoute'); } // root is filtered}  

You MvcEvent :: EVENT_ROUTE event:

  callback to the public Can also attach functions (MvcEvent $ e) {$ e- & gt; GetApplication () - & gt; GetEventManager () - & gt; Attach (MvcEvent :: EVENT_ROUTE, Function (EventInterface $ E) {// Check the route and whatever you want, $ matchedRouteName = $ Event-> getRouteMatch () -> getMatchedRouteName (); if ( $ MatchedRouteName = 'admin') {// or whatever you want to see / check that the user is the administrator}}};}  

Not only MvcEvent :: EVENT_ROUTE < / Code>, there are too many events, such as MvcEvent :: EVENT_DISPATCH . You just have to attach a callback function! For the complete list of all MVC events, see the link!

< / Div>

Comments