[英]Get controller folder name in codeigniter?
if i have folder in controller like this : 如果我在控制器中有这样的文件夹:
controller/folder/class/method
how to get current folder, 如何获取当前文件夹,
for class : $this->router->class
对于类:
$this->router->class
for method : $this->router->method
对于方法:
$this->router->method
How can i get the folder name or full path ??? 我如何获取文件夹名称或完整路径?
You can check out URI class manual 您可以查看URI类手册
To get current uri: 要获取当前的uri:
$this->uri->uri_string()
To get controller folder in you example: 在您的示例中获取控制器文件夹:
$this->uri->segment(1)
controller/folder/class/method
Try it : 试试吧 :
echo $this->uri->segment(1);
It will display your foldername under controller 它将在控制器下显示您的文件夹名称
Ex : 例如:
/controller/stackoverflow/class/method
o/p : stackoverflow
You can use $this->router->fetch_directory() 您可以使用$ this-> router-> fetch_directory()
From system/core/Router.php
: 从
system/core/Router.php
:
/**
* Fetch the sub-directory (if any) that contains the requested controller class
*
* @access public
* @return string
*/
function fetch_directory()
{
return $this->directory;
}
I've always used: 我一直使用:
$this->uri->segment(1)
To get my controller name. 获取我的控制器名称。 Not sure if this is the since you're looking for a folder name.
由于您要查找文件夹名称,因此不确定是否是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.