M. A.
M. A.

Reputation: 289

KO3 Routing with directory

Have a problem with creating route for my controller.

I'd like to organize controllers in directories and I put one controller into users directory. However I have no idea how to access it.

There's 127.0.0.1/login/index and I want it to look like this 127.0.0.1/users/login. I moved controller into users directory however have no idea how to force my route to work correctly.

Following route is not working:

Route::set('users', 'users(/<controller>(/<action>))')
    ->defaults(array(
        'controller' => 'login',
        'action'     => 'index',
    ));

Upvotes: 0

Views: 214

Answers (1)

biakaveron
biakaveron

Reputation: 5483

Route has a directory param, use it:

Route::set('users', 'users(/<controller>(/<action>))')
    ->defaults(array(
        'directory'  => 'users',
        'controller' => 'login',
        'action'     => 'index',
    ));

Also you can pass directory as dynamic route param:

Route::set('users', '<directory>(/<controller>(/<action>))')
    ->defaults(array(
        'controller' => 'login',
        'action'     => 'index',
    ));

Here we dont need default directory value because its required. You can set range of values using regex (third arg in Route::set() method).

PS. I like short routes for account actions:

Route::set('users', '<action>', array('action' => '(login|logout|register)'))
        ->defaults(array(
          'controller' => 'account',
        ));

So, http://example.com/login and http://example.com/logout will work.

Upvotes: 1

Related Questions