CodeIgniter Forums
CI and var scope - problems - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: CI and var scope - problems (/thread-45841.html)

CI and var scope - problems - El Forum - 10-08-2011

Hi guys, I am with a problem/ doubt about how to use CI correctly...
I'll explain with a simple example.
I have 2 classes / models. The first like example:

class Class1_model extends CI_Model
    protected $var1;
    protected $var2;

    function __construct() {
        $this->var1 = '';
        $this->var2 = '';

    // gets and sets and more code.... blablablz.. Ok
Above is a simple class, working fine.. OK

Now, I have another class, that contain one var that is object from Class1;

class Class2_model extends CI_Model
    protected $varrr1;
    protected $var_class1;

    function __construct() {

        // main problem - I load model class to use it as var
        $this->var_class1 = $this->class1_model;
        $this->varrr1 = '';

    // gets and sets and more code.... blablablz.. Ok

Fine... class2 working alone..

Now, in my controller I need create one object model from class1... OK. I load the model and populate with get and sets.
The problem:
In same controller, I call second class/model, and.... the content from class1 loaded before, disappears!
CI doesn't respect the scope !!
This is a simple example, but I use CI for more advanced class... and have many problems with scope Sad
I am used similar classes in Java and .NET, and I have no problems.

Someone have any tips?