【问题标题】:CI Instances functionCI 实例功能
【发布时间】:2014-03-17 09:00:01
【问题描述】:

我在这里四处寻找可以帮助我了解全球化变量和 CI 实例所需的帖子。我发现了这篇很棒的帖子。

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

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您在类中定义函数,因此您需要将其称为实例方法

    $this->CI()->module = $this->module = $this->router->fetch_module();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-30
      • 2011-08-08
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      相关资源
      最近更新 更多