slimcontroller
slimcontroller copied to clipboard
Named Routes
Is it possible to have Named Routes, which I can then use in $app->UrlFor() ?
Yes,
By default routes are named with their controller:action so:
$this->app->addRoutes(array(
'/bla' => array('get' => 'Controller:index')
));
$this->app->urlFor('Controller:index'); // -> "/bla"
One way to specify the name of the routes is to do something like:
$app->addControllerRoute('/foo', 'PostsController:indexAction')->via('GET')->name('posts_path');
yes adding routes name in the array would be much appreciated
I add new controller by:
addControllerRoute('hello', 'Index:index')->via('GET')->name('name');
and i have problem with
Invalid argument supplied for foreach()
Location:lib/vendor/slim/slim/Slim/Router.php in handleError , line 147
exactly is:
protected function processGroups()
{
$pattern = "";
$middleware = array();
foreach ($this->routeGroups => NULL
what i'm doing wrong?
Hmm.
I just tried
$application->addControllerRoute('/hello', 'Home:index')->via('GET')->name('name');
And it worked fine. Could the problem be somewhere else?