Kohana 3获取当前的控制器/动作/参数 [英] Kohana 3 get current controller/action/arguments

查看:55
本文介绍了Kohana 3获取当前的控制器/动作/参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Kohana 2中,您可以轻松地获得如下信息:

In Kohana 2 you could easily get that information like this:

echo router::$controller;
echo router::$method;
echo router::$arguments[0-x];

任何想法在Kohana 3中如何工作?

Any idea how that works in Kohana 3?

提前谢谢!

推荐答案

从控制器内部:

$this->request->controller

$this->request->action

$this->request->param('paramname')

与K3中的K2参数不同,可通过您在路线中定义的kay来访问.

Unlike K2 arguments in K3 are accessed via kays which you define in your routes.

例如以以下网址为例:

Route::set('default', '(<controller>(/<action>(/<id>)))')    
    ->defaults(array('controller' => 'welcome', 'action' => 'index')); 

要访问您要调用的"id"参数

To access the "id" argument you'd call

$this->request->param('id')

您无法通过param()方法访问控制器/操作参数.

You can't access the controller / action arguments from the param() method.

请注意,您还可以使用Request::instance()获取全局(或主")请求实例.

Note, you can also use Request::instance() to get the global (or "master") request instance.

有关更多信息,请参见 K3指南

For more information see the K3 guide

这篇关于Kohana 3获取当前的控制器/动作/参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆