Я недавно взял фреймворк Codeigniter, но похоже застрял с проблемой.
Всякий раз, когда я использую автозагрузчик модели, он дает мне ту же ошибку: - «Имя модели, которое вы загружаете, является именем ресурса, который уже используется:»
Если вам нужен мой код для решения проблемы. В моем коде я использую JQuery/Ajax. Он делает вызов контроллера "Encounter".
Разумно проверить, вызываю ли я автоматически загружаемую модель где-нибудь, но я не настолько далеко, насколько я проверял.
Я немного изменил код, чтобы исключить ненужные части.
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();
}
}
Вот target_model:
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));
}
}