CodeIgniter Forums
CI and var scope - problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI and var scope - problems (/showthread.php?tid=45841)



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

[eluser]mestresan[/eluser]
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:

Code:
class Class1_model extends CI_Model
{
    protected $var1;
    protected $var2;

    function __construct() {
        parent::__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;


Code:
class Class2_model extends CI_Model
{
    protected $varrr1;
    protected $var_class1;

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

        // main problem - I load model class to use it as var
        $this->load->model('class1_model');
        $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?

thanks