• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI and var scope - problems

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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.