I have recently picked up the framework Codeigniter, but I seem to be stuck with a problem.
Whenever I use the model autoloader it gaves me the same error:
- "The model name you are loading is the name of a resource that is already being used: "
In case you need my code to solve the problem. In my code I am using JQuery/Ajax. It makes a call to controller "Encounter".
The reasonable thing to check is if I'm calling the automatically loaded model anywhere, but I'm not as far as I checked.
I have changed the code a bit to leave out unimportant parts.
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();
}
}
Here is the 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;
}
}
My autoload:
$autoload['model'] = array('encounter_model');
Class I'm trying to autoload:
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));
}
}