CodeIgniter:如何获取控制器,操作,URL信息 [英] CodeIgniter: How to get Controller, Action, URL information

查看:97
本文介绍了CodeIgniter:如何获取控制器,操作,URL信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下URL:

  • http://backend.domain.com/system/setting/edit/12
  • http://backend.domain.com/product/edit/1

如何从这些URL获取控制器名称,动作名称.我是CodeIgniter新手.是否有任何辅助功能来获取此信息

How to get controller name, action name from these URLs. I'm CodeIgniter newbie. Are there any helper function to get this info

例如:

$params = helper_function( current_url() )

$params变成

array (
  'controller' => 'system/settings', 
  'action' => 'edit', 
  '...'=>'...'
)

推荐答案

您可以使用 URI类:

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc

我还被告知可以进行以下工作,但是目前无法测试:

I've also been told that the following work, but am currently unable to test:

$this->router->fetch_class();
$this->router->fetch_method();

这篇关于CodeIgniter:如何获取控制器,操作,URL信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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