Recommend this page to a friend! |
Classes of Alexey Dodonov | mezon PHP Router Library | README.md | Download |
|
DownloadRoutingIntroMezon provides simple routing class for your needs. InstallationJust print in console
And that's all ) Reasons to useThe mezon/router is more than 25 times faster then klein/klein router (in some cases). Simple routesRouter allows you to map URLs on your php code and call when ever it needs to be calld. Router supports simple routes like in the example above - example.com/contacts/ Each Application object implicity creates routes for it's 'action[action-name]' methods, where 'action-name' will be stored as a route. Here is small (as usual)) ) example:
And this code
will create router object and loads information about it's actions and create routes. Strictly it will create two routes, because the class MySite has only two methods wich start wth 'action[Suffix]'. Method 'someOtherPage' will not be converted into route automatically. But we can still use this method as a route handler:
And you also can use stati methods:
We just need to create it explicitly. We can also use simple functions for route creation:
One handler for all routesYou can specify one processor for all routes like this:
Note that routing search will stops if the '*' handler will be found. For example:
In this example route /index/ will never be reached. All request will be passed to the '*' handler. But in this example:
route /contacts/ will be processed by it's own handler, and all other routes (even /index/) will be processed by the '*' handler. Route variablesAnd now a little bit more complex routes:
Here: i - any integer number a - any [a-z0-9A-Z_\/\-\.\@]+ string il - comma separated list of integer ids s - any string All this variables are passed as second function parameter wich is named in the example above - $Variales. All variables are passed as an associative array. Request types and first steps to the REST APIYou can bind handlers to different request types as shown bellow:
|