Home

Awesome

Phalcon-autorouter

Version 2.0

Example full application with various libraries included in this example

Change log

Dependencies

Installation

How it works ?

AutoRoutin plugin route application based on URL in order /module/controller/action/. When module, controller or action have not been found AutoRoute plugin automaticaly shift route for specific part and set it for next part eg.: /module/controller/action/ where module is not been found then automatic default module have been used and module part is set as an "controller". Same process happening until all parts are defined or found. Error action is being used when no default actions are set in configuration.

Example

Url: /manager/param/value/

Url will be routed to: manger module with indexAction rest of parameters behind /manager/ will be parsed and accessible in order /key/value/ in this case $this->request->getParam('param') will return value.

Url: /admin/my-own/param/value/

Url will be routed to: manger module to myOwnController and indexAction rest of parameters behind /manager/my-own/ will be parsed and accessible in order /key/value/ in this case $this->request->getParam('param') will return value.

Accessing params

From controller is possible to access params from request

//url /admin/mycontroller/param/value/
$param = $this->request->getParam("param");

The request will return value.

Accessing params with url map

In any reqeust it can be sat some map for url params.

//url: /admin/mycontroller/mycustomvalue/mynextvalue/
$this->request->setMap(new \Core\Http\Url\Map("/:mycustomname/:mynextname");
$myParam1 = $this->request->getParam("mycustomname");// returns mycustomvalue
$myParam2 = $this->request->getParam("mynextname");//returns mynextvalue

To access part's what have been shifted (/admin/mycontroller/) durring auto routing process we can use

$this->request->getParam("module"); // to access module name ( admin )
$this->request->getParam("controller"); //to access url controller value
$this->request->getParam("action"); //to access url action name 

ENJOY!