在Kohana 3.2中检索请求参数(例如控制器和操作)

时间:2022-10-13 13:14:14

I have my controllers with the following extensions:

我的控制器有以下扩展名:

Controller_Login extends Controller_Layout Controller_Layout extends Controller_Template

Controller_Login扩展Controller_Layout Controller_Layout扩展Controller_Template

so that all controllers (processing user urls) will pass through Controller_Layout. In my controller_Layout, I'm trying to retrieve the controller and action url values in order to bind them and display them in my layout view.

这样所有控制器(处理用户URL)都将通过Controller_Layout。在我的controller_Layout中,我正在尝试检索控制器和操作url值,以便绑定它们并在我的布局视图中显示它们。

Calling this echo $this->request->param('controller'); returns nothing (empty string), while calling echo $this->request->param(); return an empty array. Clearly nothing is found in the request.

调用这个echo $ this-> request-> param('controller');什么都不返回(空字符串),同时调用echo $ this-> request-> param();返回一个空数组。显然,请求中没有找到任何内容。

I'm wondering if this is because I'm trying to retrieve the request values from the parent controller of where the request is actually handled. Idealy i'd like to handle this through my parent controller (controller_Layout) since every page request will need to make this call to retrieve the controller and action value

我想知道这是否是因为我正在尝试从父控制器检索请求实际处理的位置。 Idealy我想通过我的父控制器(controller_Layout)处理这个问题,因为每个页面请求都需要进行此调用以检索控制器和操作值

Any ideas?

有任何想法吗?

1 个解决方案

#1


2  

To get the current Requests controller name, use $this->request->controller() instead of $this->request->param('controller'). Same goes for current action, they aren't variable parameters so they're accessed this way.

要获取当前的Requests控制器名称,请使用$ this-> request-> controller()而不是$ this-> request-> param('controller')。对于当前操作也是如此,它们不是可变参数,因此它们以这种方式访问​​。

And yes, you can handle those in the parent controller, keep it DRY :)

是的,你可以处理父控制器中的那些,保持干燥:)

#1


2  

To get the current Requests controller name, use $this->request->controller() instead of $this->request->param('controller'). Same goes for current action, they aren't variable parameters so they're accessed this way.

要获取当前的Requests控制器名称,请使用$ this-> request-> controller()而不是$ this-> request-> param('controller')。对于当前操作也是如此,它们不是可变参数,因此它们以这种方式访问​​。

And yes, you can handle those in the parent controller, keep it DRY :)

是的,你可以处理父控制器中的那些,保持干燥:)