[英]Get controller name and subfolder in codeigniter
I have my controllers organized in subfolders, like this: 我将控制器组织在子文件夹中,如下所示:
folder1/controller1
folder1/controller2
folder2/controller1
folder2/controller2
I need to get both the controller and the subfolder name, but right now I can only get the controller name using 我需要同时获取控制器名称和子文件夹名称,但是现在我只能使用
$CI =& get_instance();
$CI->router->class;
I also tried this one: 我也尝试过这个:
$CI->uri->uri_string()
But if I call my controller with a method, it will return it too, like this 但是,如果我使用方法调用控制器,它也会返回它,就像这样
full url: 完整网址:
http://localhost/codeigniter/folder1/controller1/index
will return 将返回
folder1/controller1/index
instead of 代替
folder1/controller1
I can do this by using the class name to remove the methods and arguments, but I want to know if there is a better solution. 我可以通过使用类名称删除方法和参数来做到这一点,但是我想知道是否有更好的解决方案。
Thanks in advance! 提前致谢!
print_r($this->router);
Here you have all the other goodies! 在这里,您还有其他所有的好东西!
In you case you want $this->router->directory
如果您需要
$this->router->directory
It returns folders/to/controller/
with a trailing /
. 它返回
folders/to/controller/
后跟/
。
Example: 例:
Adress: www.example.com/folder1/controller1 地址:www.example.com/folder1/controller1
echo $this->router;
Outputs: 输出:
folder1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.