我想显示在codeigniter中调用函数的模块名。例如,如果有两个模块,abc和xyz。它们都有控制器abc和xyz,它们的代码片段类似如下:
class Abc{
function __construct() {
parent::__construct();
}}
和
class Xyz{
function __construct() {
parent::__construct();
}
function index() {
$this->load->module('abc');
echo $this->router->fetch_module();
}
}
现在,当我调用模块xyz的索引函数时,我得到的输出为'abc',我想要在其中显示函数存在的模块名称,即xyz。有什么解决办法吗?
这样怎么样?我以前没有使用过CodeIgniter HMVC,所以如果我错过了一些明显的东西,我很抱歉。
class Abc{
protected $rootModuleName;
function __construct() {
parent::__construct();
}
function setRootModuleName($name) {
$this->rootModuleName = $name;
}
}
class Xyz{
function __construct() {
parent::__construct();
}
function index() {
$this->load->module('abc');
$this->abc->setRootModuleName(__CLASS__); //or you could just pass the string 'Xyz'
//This call would need to somehow make use of the $rootModuleName property
echo $this->router->fetch_module();
}
}