Loading...

Router

The router allows us to assign to a chosen path the behaviour of the system. Based on the path, the system knows to which controller it should direct the movement and also with the help of the class router.class.php found in the core, allows us to do redirect it to other controllers by routing name.

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.
  1. 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.
  2. 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.
  3. 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=adminInstallController 
Variable #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
Example of use for
[/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')

We are continually working to improve Windu CMS!

By visitng the Windu website you will be kept up to date on new developments concerning the CMS.

2014-05-19 Battle Report

Since the release of Windu 3.0 we have we have done a lot of stuff to our CMS. The most important event in the near future will be the upgrade to version 3.1, which means a...

2014-03-25 Windu 3.0 - list of changes

After many months of challenges, new version of our CMS is finally out! We've decided to drop the idea Windu 2.4 and go for 3.0 straight away due to amount of changes...

2013-06-17 Update - Windu CMS rev 1432

New Windu CMS update is available for download at update server! Update includes several changes in our system: Pinning of tabs - allows fast navigation between open...

Buy a PRO license!

Activate loads of add-ons in your windu!

Buy a PRO license