Creating a route? Within a controller action_index? Kohana

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:53:22

问题


I am working with kohana, because development goes so pretty fast. Now I want to achieve something which I can't really think of a workaround for.

What I want to achieve, there is a controller. It's called Controller_Restaurants But those restaurants, are grouped by provinces and after province is clicked they are grouped by a city, and then a list of the restaurants is shown up.

All cities and provinces are already added to there specific database with fields.

I want to create a route in my controller. So can I achieve a following link:

domain/restaurants/province/city/restaurant-name

?

Or am I thinking like a douche and should I solve this otherwise?


回答1:


Build your routing like this:

Route::set('restaurants', 'restaurants(/<province>(/<city>(/<name>))))',
    array(
        'controller' => 'restaurants',
        'action' => 'index',
    ));

It should work like this.




回答2:


It is possible to create routes inside a controller in Kohana, but it won't help you solve your problem because routing has already happened.

What you need to do is create a route with optional parameters as suggested by @kingkero:

restaurants(/<province>(/<city>(/<name>)))

Then access the parameters in the URL from the controller like so:

$province = $this->request->param('province');
...


来源:https://stackoverflow.com/questions/30282535/creating-a-route-within-a-controller-action-index-kohana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!