non*_*.cs 120 php codeigniter codeigniter-2
我有这些网址:
如何从这些URL获取控制器名称,操作名称.我是CodeIgniter的新手.是否有任何帮助函数来获取此信息
例如:
$params = helper_function( current_url() )
Run Code Online (Sandbox Code Playgroud)
哪里$params
变得像
array (
'controller' => 'system/settings',
'action' => 'edit',
'...'=>'...'
)
Run Code Online (Sandbox Code Playgroud)
Sam*_*son 210
您可以使用URI类:
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
Run Code Online (Sandbox Code Playgroud)
我也被告知以下工作,但我目前无法测试:
$this->router->fetch_class();
$this->router->fetch_method();
Run Code Online (Sandbox Code Playgroud)
Phi*_*eon 132
您应该这样做,而不是使用URI段:
$this->router->fetch_class(); // class = controller
$this->router->fetch_method();
Run Code Online (Sandbox Code Playgroud)
这样,即使您位于路由URL,子域等后面,您也知道始终使用正确的值.
小智 28
这些方法已弃用.
$this->router->fetch_class();
$this->router->fetch_method();
Run Code Online (Sandbox Code Playgroud)
您可以改为访问属性.
$this->router->class;
$this->router->method;
Run Code Online (Sandbox Code Playgroud)
URI路由方法fetch_directory(),fetch_class(),fetch_method()
对于属性
CI_Router::$directory
,CI_Router::$class
并且CI_Router::$method
公开和他们各自fetch_*()
不再做任何其他事情只返回属性 - 保留它们是没有意义的.这些都是内部的,未记录的方法,但我们现在选择弃用它们以保持向后兼容性以防万一.如果你们中的一些人已经使用过它们,那么你现在可以只访问这些属性:
Run Code Online (Sandbox Code Playgroud)$this->router->directory; $this->router->class; $this->router->method;
Sta*_*arx 10
作为补充
$this -> router -> fetch_module(); //Module Name if you are using HMVC Component
Run Code Online (Sandbox Code Playgroud)
更新资料
答案是在2015年添加的,现在不推荐使用以下方法
$this->router->fetch_class(); in favour of $this->router->class;
$this->router->fetch_method(); in favour of $this->router->method;
Run Code Online (Sandbox Code Playgroud)
嗨,您应该使用以下方法
$this->router->fetch_class(); // class = controller
$this->router->fetch_method(); // action
Run Code Online (Sandbox Code Playgroud)
为此,但要使用此功能,您需要从扩展钩子,CI_Controller
并且它像一个吊饰一样工作,您不应该使用uri段