以codeigniter格式获取控制器文件夹名称


Get controller folder name in codeigniter?

如果我在控制器中有这样的文件夹:

controller/folder/class/method

如何获取当前文件夹,

对于类别:$this->router->class

方法:$this->router->method

如何获得文件夹名称或完整路径??

controller/folder/class/method

Try it:

echo $this->uri->segment(1);

它将显示控制器

下的文件夹名

示例:

/controller/stackoverflow/class/method
o/p : stackoverflow

您可以查看URI类手册

获取当前uri:

$this->uri->uri_string()

在你的例子中获取控制器文件夹:

$this->uri->segment(1)

可以使用$this->router->fetch_directory()

From 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;
 }

我一直使用:

$this->uri->segment(1)

获取控制器名称。

不确定这是否是文件夹名称,因为您正在寻找文件夹名称。