Route · Mecha CMS

Do something if URL path matched with pattern.

$route::set()

Author: Taufik Nurrohman · 199 Views

Tweet

Set a route.

Route::set($id = null, $fn = null, $stack = null, $pattern = false);

Example:

Route::set('blog/%i%', function($step = 1) {
    // here, `$step` will return `4` if we are in `‌http://mecha-cms.com‌/blog/4`
    // and will return `1` if we are in `‌http://mecha-cms.com‌/blog`
});

Note: Default $stack value is 10.

To set multiple routes:

Route::set(['blog/%s%/%i%', 'blog/%s%', 'blog/%i%', 'blog'], function($slug = "", $step = 1) { … });

The code above is equal to:

Route::set('blog/%s%/%i%', function($slug = "", $step = 1) { … }, 10);
Route::set('blog/%s%', function($slug = "", $step = 1) { … }, 10.1);
Route::set('blog/%i%', function($slug = "", $step = 1) { … }, 10.2);
Route::set('blog', function($slug = "", $step = 1) { … }, 10.3);