Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Named Routes #29

Open
Patabugen opened this issue Jul 7, 2014 · 5 comments
Open

Named Routes #29

Patabugen opened this issue Jul 7, 2014 · 5 comments

Comments

@Patabugen
Copy link

Is it possible to have Named Routes, which I can then use in $app->UrlFor() ?

@yaworsw
Copy link
Contributor

yaworsw commented Jul 8, 2014

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"

@yaworsw
Copy link
Contributor

yaworsw commented Jul 8, 2014

One way to specify the name of the routes is to do something like:

$app->addControllerRoute('/foo', 'PostsController:indexAction')->via('GET')->name('posts_path');

@mouhsinelonly
Copy link

yes adding routes name in the array would be much appreciated

@pioter
Copy link

pioter commented Sep 19, 2014

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?

@yaworsw
Copy link
Contributor

yaworsw commented Sep 20, 2014

Hmm.

I just tried

$application->addControllerRoute('/hello', 'Home:index')->via('GET')->name('name');

And it worked fine. Could the problem be somewhere else?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants