Route · Mecha CMS

Do something if URL path matched with pattern.

$route::is()

Author: Taufik Nurrohman · 195 Views

Tweet

Check whether current URL path is matched with the given route pattern.

Route::is($id, $fail = false, $pattern = false);

Example:

if (Route::is('blog/%s%')) { … }

This method will return the route data, parsed from the current URL path; or false:

__test__(
    Route::is('blog/%s%/%i%'),
    Route::is('blog/$'),
    Route::is('blog/$', 0)
);

Result:

[
    'pattern' => 'blog/%s%/%i%',
    'path' => 'blog/archive/4',
    'lot' => ['archive', 4]
]
false
0