我在这里四处寻找一篇文章,它可以帮助我了解全球化的变量和CI实例所需的内容。我找到了这个伟大的职位。
instance() in Codeigniter: Why assign it to a variable?
这方面的问题是,当我在自己的应用程序中尝试时,我收到了以下错误。
Fatal error: Call to undefined function CI() in .../application/core/MY_Controller.php on line 6我不知道这是为什么。有人能详细说明一下吗?
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public $module;
public function __construct() {
parent::__construct();
CI()->module = $this->module = $this->router->fetch_module();
}
function CI()
{
static $CI;
isset($CI) || $CI = CI_Controller::get_instance();
return $CI;
}
}发布于 2014-02-17 21:44:08
在类中定义函数,因此需要将其作为实例方法引用
$this->CI()->module = $this->module = $this->router->fetch_module();https://stackoverflow.com/questions/21839685
复制相似问题