Problem class objects and CI object |
[eluser]bramb79[/eluser]
Anyone can offer me some advise on the following: I am working on a project where I want to set my up data objects along the line of http://ellislab.com/forums/viewthread/49403/P15/#239838. So I have a for example: Code: class Usermodel extends MY_Model { I can then create an instance of a User (new User()), put some values in the User object, for example a "name", and then call $this->getName() on the User object to return me the username (in an appropriate format). I also want to be able to reference other models and functions from within the CI object. For the User example that would probably mean something like: Code: $this->CI->load->model('groupmodel'); Now my problem is, is that as soon as I load the CI object in the User class, in MyClass or extend MyClass with Model (which it is most related too), the CI object (which is quite large) becomes part of the class. When I create a new instance of that class. For example: Code: $user = new User(); Code: $this->CI =& get_instance(); Code: $CI =& get_instance(); Anyone can help me with a better solution. Your help would be much appreciated. Thanks.
[eluser]wiredesignz[/eluser]
$CI =& get_instance() only returns a reference to CI, it does not make a copy of the super object (controller).
[eluser]bramb79[/eluser]
[quote author="wiredesignz" date="1218593779"]$CI =& get_instance() only returns a reference to CI, it does not make a copy of the super object (controller).[/quote] Thanks for the info. Deep down I knew that already (had read it before). But that still leaves me with my question. What I would ideally want (or at least I think I do) is to make $CI (after stating $CI =& get_instance()) available in my entire class. Stating it in the constructor does not help. I think it is out of scope for other methods in the class. Putting $this->CI & get_instance() in the constructor does bring it within scope for the other methods but when I then create a new instance of the class I end up with the CI object as part of the data of that object. |
Welcome Guest, Not a member yet? Register Sign In |