Question

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

}
Was it helpful?

Solution

It seem that you are trying to reload this model somewhere in the code. Try to search this and remove the possible duplication.

for further help see this.

The model name you are loading is the name of a resource that is already being used: base_model

OTHER TIPS

Turns out I had the following code:

class Index extends CI_Controller {

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

But I have to put the construct inside the constructor..

class Index extends CI_Controller {

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

    public function index()
    {
        $this->load->view('game');
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top