Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter-自动加载模式总是失败_Php_Codeigniter_Frameworks_Autoloader - Fatal编程技术网

Php Codeigniter-自动加载模式总是失败

Php Codeigniter-自动加载模式总是失败,php,codeigniter,frameworks,autoloader,Php,Codeigniter,Frameworks,Autoloader,我最近学习了framework Codeigniter,但似乎遇到了一个问题 每当我使用model autoloader时,都会出现相同的错误: -“您正在加载的模型名称是已在使用的资源的名称:” 以防你需要我的代码来解决问题。在我的代码中,我使用JQuery/Ajax。它向控制器发出“遭遇”呼叫 合理的检查方法是,我是否在任何地方调用自动加载的模型,但我没有检查到的程度 我对代码做了一些修改,去掉了不重要的部分 class Encounter extends CI_Controller {

我最近学习了framework Codeigniter,但似乎遇到了一个问题

每当我使用model autoloader时,都会出现相同的错误: -“您正在加载的模型名称是已在使用的资源的名称:”

以防你需要我的代码来解决问题。在我的代码中,我使用JQuery/Ajax。它向控制器发出“遭遇”呼叫

合理的检查方法是,我是否在任何地方调用自动加载的模型,但我没有检查到的程度

我对代码做了一些修改,去掉了不重要的部分

class Encounter extends CI_Controller {

    public function __construct() 
    {
        parent::__construct();
    }

    /* *
     * Summary: Load descriptive, mutative (statistical) data
     * @params: N/A
     * #return: N/A
     */
    public function startEncounter()
    {
        $encounter_id = $_POST['encounter_id'];

        switch ($encounter_id)
        {
            case 1:
                $this->load->model('target_model', 'target');
                break;
        }

        $this->target->Start();
    }
}
以下是目标_模型:

class Target_model extends CI_Model {

    //  Has the player met the target before
    public $F_hasMet = false;

    function __construct()
    {
        parent::__construct();
    }

    public function Start()
    {
        $this->SayHello();
        $this->encounter_model->CallDialog();
    }

    /* *
     * Summary: Say hello
     * @params: N/A
     * #return: N/A
     */
    public function SayHello()
    {
        $this->encounter_model->SetDialog("Hello");
        $this->F_hasMet = true;
    }

}
我的自动加载:

$autoload['model'] = array('encounter_model');
class Encounter_model extends CI_Model {

/* *
 * Summary: Interactive data
 */
public $dialog = '';

function __construct()
{
    parent::__construct();

    if ( ! $this->input->is_ajax_request()) {
        $this->output->set_status_header('401');
    }
}

/* *
 * Summary: Add or replace dialog
 * @params: Message, addition
 * #return: N/A
 */
public function SetDialog($message, $addition = true)
{
    if ($addition) {
        $this->dialog .= $message;
    } else {
        $this->dialog = $message;
    }
}

/* *
 * Summary: Displays the current dialog to the screen
 * @params: Message, addition
 * #return: N/A
 */
public function CallDialog()
{       
    $this->output
       ->set_content_type('application/json')
       ->set_header("HTTP/1.1 200 OK")
       ->set_output(json_encode($this->dialog));
}

}
我正在尝试自动加载的类:

$autoload['model'] = array('encounter_model');
class Encounter_model extends CI_Model {

/* *
 * Summary: Interactive data
 */
public $dialog = '';

function __construct()
{
    parent::__construct();

    if ( ! $this->input->is_ajax_request()) {
        $this->output->set_status_header('401');
    }
}

/* *
 * Summary: Add or replace dialog
 * @params: Message, addition
 * #return: N/A
 */
public function SetDialog($message, $addition = true)
{
    if ($addition) {
        $this->dialog .= $message;
    } else {
        $this->dialog = $message;
    }
}

/* *
 * Summary: Displays the current dialog to the screen
 * @params: Message, addition
 * #return: N/A
 */
public function CallDialog()
{       
    $this->output
       ->set_content_type('application/json')
       ->set_header("HTTP/1.1 200 OK")
       ->set_output(json_encode($this->dialog));
}

}

似乎您正试图在代码中的某个地方重新加载此模型。尝试搜索此项并删除可能的重复项

如需进一步帮助,请参阅此


原来我有以下代码:

class Index extends CI_Controller {

    public function index()
    {
        parent::__construct();
        $this->load->view('game');
    }
}
但是我必须把构造放在构造函数里面

class Index extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->view('game');
    }
}

谢谢你的时间,但蒂亚不应该是这样。即使我创建了一个全新的模型,它也会抛出同样的错误。我不认为这不能回答这个问题。我会将此标记为答案,因为提供的链接将我推向了正确的方向。