sFire PHP Framework

Template engine: Routing

All the routes that are defined in the routes.php can be used in your view. This way, if a url changes, you won't have to find the url in every view to change it.

Let say, for example, you have a route called "blog.view" in the routes.php:

Router :: get('blog/latest/view', 'blog.view') -> module('App')  -> controller('Blog')-> action('view');

You can convert the unique identifier of the route to a url in the view:

@router('blog.view') //Outputs "blog/latest/view"

If you have variables in the route, you can give them as an Array as second parameter:

routes.php:

Router :: get('blog/edit/{int}', 'blog.edit') -> module('App')  -> controller('Blog')-> action('edit');

View:

@router('blog.edit', 25) //Outputs "blog/edit/25"

You may also use an Array if you have set multiple variables:

@router('blog.edit', [25])

Of course you can use variables that are defined in your controller:

View:

@router('blog.edit', [$blog_id]) //Output "blog/edit/25"