Welcome Guest, Not a member yet? Register   Sign In
Model overwriting other model data
#1

[eluser]Flipside Tech[/eluser]
I have some total weirdness happening with models that share the same member name.

Example:
Code:
class Category_model extends Model {
    protected $id;
    protected $name;
    protected $uri;
    function Category_model() {
        parent::Model();
        $this->init();
    }
    function init() {
    $this->id = 0;
    $this->name = "";
        $this->uri = "";
    }
    function getName() { return $this->name; }
    function setName($str) { $this->name = $str; }
    function getURI() { return $this->uri; }
    function setURI($str) { $this->uri = $str; }    
}
class Post_model extends Model {
    protected $id;
    protected $name;
    protected $uri;
    function Post_model() {
        parent::Model();
        $this->init();
    }
    function init() {
    $this->id = 0;
    $this->name = "";
        $this->uri = "";
    }
    function getName() { return $this->name; }
    function setName($str) { $this->name = $str; }
    function getURI() { return $this->uri; }
    function setURI($str) { $this->uri = $str; }    
}

Ok, simple right. Now in the controller:
Code:
$this->post_model->setURI("post_uri");
echo $this->post_model->getURI();   // outputs post_uri

$this->category_model->setURI("category_uri");
echo $this->category_model->getURI();   // outputs  category_uri

echo $this->post_model->getURI();   // outputs category_uri .... ummmm ... what up?

Weird. Help.
#2

[eluser]Flipside Tech[/eluser]
Fixed it by changing the following in the CodeIgniter Model class:

Code:
//$this->_assign_libraries( (method_exists($this, '__get') OR method_exists($this, '__set')) ? FALSE : TRUE );
$this->_assign_libraries(FALSE);

Can someone tell me why that fixed it?




Theme © iAndrew 2016 - Forum software by © MyBB