开发者

Kohana 2.3/3 routing?

开发者 https://www.devze.com 2023-01-12 21:11 出处:网络
I\'ve been thinking how to make something like this in Kohana: domain.com/variable the \"variable\" is the identifier for a user.

I've been thinking how to make something like this in Kohana:

domain.com/variable

the "variable" is the identifier for a user.

So, is this possible?

http://domain.com/username/controller/action

If yes, can you point me to the 开发者_开发知识库right direction, please?

Thanks.


What happens if you have a page named "contact" and a user signs up with "contact" as a username. Which page will be displayed?

Here is an example I threw together for you.

// Pages that aren't users.
Route::set('static', '<action>', array('action' => 'sitemap|faq|terms|privacy|credits'))
->defaults(array(
    'controller' => 'static'
));

// User routing
Route::set('user', '<username>(/<controller>(/<action>))')
->defaults(array(
    'controller' => 'user',
    'action' => 'index'
));

So when this URL is called

http://example.com/sitemap

the first route is used and when

http://example.com/arnold

is called your user class and index method would be called. You can access the username variable with:

$this->request->param('username');

If you have any more questions, feel free to ask.

0

精彩评论

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

关注公众号