Welcome Guest, Not a member yet? Register   Sign In
multiple elements call same models
#1

[eluser]Lenouv[/eluser]
Hello.
Sorry for my english, i'm a newbie in english like in codeigniter. I'm french and the french community is dying.

I'm using codeigniter for a professional project (10k€). I'm using the double linked list with heritage in order to manipulate the datas:

controller Listmanager extends CI_Controller
controller Listelement extends CI_Controller with a database table 'list' and a model Listelement_model
controller Typemanager extends Listmanager
controller Typeelement extends Listelement with a database table 'type' and a model Typeelement_model.

It's just an example.

When i want to update two or more elements, this bug appears:
The first typeelement call the model list method and the model type method in order to save it. It works.
The second typeelement call the model list or type ... and this error appears:


Severity: Notice

Message: Undefined property: Typeelement::$Listelement_model

Filename: controllers/listelement.php

Line Number: 77


my code :
Code:
$this->load->model(array('Listelement_model'));
        $this->list_id =  $this->Listelement_model->saveAll($this->list_id, $this->is_first, $this->previous->_getListId(), $this->next->_getListId());
        return $this->list_id;

The only way i found is to rename the model object like this : http://ellislab.com/codeigniter/user-gui...ml#loading

But ... i will have to work with more than 2 or 3 elements in the list, how can i in order to not rename the model object every time i need to insert or update a element?

Thx
bye.
#2

[eluser]Lenouv[/eluser]
Re-

The "only" way i found doesn't work :/
How i do it:
- I generate an aleatory name for the model depends on the list_id of the element
- I call the model with this new model_name
- I call the model function to save or update element.

My code:
Code:
public function _save($list_id = NULL){
        $model_name = 'Typeelement_model';
        if($list_id != NULL && is_int($list_id))
            $model_name .= $list_id.mt_rand(1,100);
        $this->load->model('Typeelement_model', $model_name);
        $this->$model_name->saveAll($datas);
}

How can I do?
#3

[eluser]jvicab[/eluser]
I am not sure what your intention is using: $this->load->model(array('Listelement_model'));
If you explain to me what you need to be done, I would help you to find another way to get it done.
#4

[eluser]Lenouv[/eluser]
Sorry i not using array('listelement_mdel'), it's just a test.

I'm found another way yesterday but this is lower.




Theme © iAndrew 2016 - Forum software by © MyBB