Structure of router.ini file
Each plugin has its own file "our_plugin/config/router.ini" which looks like this:[/image/#ekey/#width/#height/] name=image controller=imageController [/image/#ekey/#width/#height/#transform/] name=imageTransform controller=imageController
Given path is defined in the form of 3 rows.
- In the first one in square brackets, we're defining an address which will be after our main system folder, so if our system is at "www.address.com/windu/" then our routing defines path "www.address.com/windu/image/urtydhe/100/200". Hashtag # tells us that there will be a paramater that will be changed, a variable (equivalent of #_GET variable) and if we enter a word without # before it then the system will look for this word, based on this we can define concrete routing.
- In the second line we have a routing name which can be used to call out an address with use of the router in our controller.
- At the end we define the name of the controller onto which traffic will be directed from a given path.
Vriable #action
In our router we can also use one special variable called #action[/admin/install/] name=admin-install controller=adminInstallController [/admin/install/#action/] name=admin-install-action controller=adminInstallController [/admin/install/#action/#id/] name=admin-install-action-id controller=adminInstallControllerVariable #action is downloaded by our router and it refers to method inside of controller onto which traffic is directed. If we won't define variable #action then system will call our default method index() and if we set #action to 'my_function' then system will call out methond 'my_function' from controller.
Overwriting paths
Routers from plugins are merged into one and the system searches path backwards so the last plugin in config can overwrite a given path. If plugin "front" has a defined path [/] (simple address entry without any variables) then by adding at the end of the file "app/includes/config.php" in constant plugins our plugin and in its router.ini file we add [/] variable we can overwrite the behaviour of the system. In such a case it is not the plugin front but our plugin will be directing behaviour of the system to that path. Pay attention to this while adding a plugin.Using router class for redirects
In the system we have a class, router.class.php, which has many functions allowing redirections or returning paths from routing. Examples of the use of router:
route($target, $variables = array(), $anchor = null)
Generates a redirecting link to a specified routing and returns a path
- $target - is the name of a specific routing given as a parameter name in router.ini
- $variables - is a table with parameters, in other words variables which should be assinged to the path
- $anchor - what's supposed to be at the end of path after # sign
[/admin/install/#action/#id/] name=admin-install-action-id controller=adminInstallController
route('admin-install-action-id',array('action'=>'actionName','id'=>10))
redirect($target, array $query = array(), $permanent = false, $anchor = null)
Redirects to a specified path based on routing
- $target - is the name of a specific routing given as a parameter name in router.ini
- $query - is a table with parameters, in other words variables which should be assinged to the path
- $permanent - sets redirection 301
- $anchor - what's supposed to be at the end of path after # sign
redirect('admin-install-action-id',array('action'=>'actionName','id'=>10),true)
back($request,$anchor = 'mp=admin.message.success')
Returns onto a path from which it was called out in the previous step
- $request - variable $this->request recived from controller level
- $anchor - what's supposed to be at the end of path after a redirect in form of the variable get or an anchor
back($this->request,'mp=admin.message.success')
reload($message = 'admin.message.success',$messageType = 'mp',$force = false)
Reloads current page
- $message -variable of a communicate loaded from language keys
- $messageType - type of message. mp - positive, mn - negative
reload('admin.message.success','mp')