开发者

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',
    ));


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜