Welcome Guest, Not a member yet? Register   Sign In
Returning library object without CI super obj info
#1

[eluser]RJ[/eluser]
Hi,

Silly little question, I want to return a library object without all the CI info that is loaded when we assign &get;_instance to a var.

Is there a cleaner way than this?
Code:
public function data()
        {
                $this->_CI = '';
                return $this;
        }

// I load the ci instance as such
public function __construct($props = array())
        {              
                $this->_CI =&get;_instance();

Thank you
#2

[eluser]WanWizard[/eluser]
Any particular reason why you would want this?

It is added by reference, so it doesn't take up any space.
#3

[eluser]RJ[/eluser]
Cleaner to look at for debugging, that's all.
#4

[eluser]jefc[/eluser]
I was about to post a similar question to this but found this one so thought I'd resurrect it.

I understand that being added by reference means it takes up no extra space, but it still feels messy! One way round it I have used some of the time is to assign to a local variable each time I need to use a CI resource from in a library. So instead of
Code:
$this->CI =& get_instance();
in the library constructor I am using
Code:
$CI =& get_instance();
in the necessary function. This way the variable is local to the function. However, I now have that latter line of code all over the place. Not very DRY!

My application is pretty complex, with a significant number of my own libraries, and I have various nested objects, including array of objects inside other objects. It is really useful to be able to view an object as a whole and if you see the whole CI superobject a few times in there it gets very unwieldy!

Thanks in advance for any input.
#5

[eluser]CroNiX[/eluser]
Are you doing a dump of $this or something while debugging and stumbling through the entire CI object? You can always just dump the specific object.

Code:
var_dump($this->your_library_object)

Code:
$CI =& get_instance();
var_dump($CI->your_library_object);

Its much better to just bring the CI object into your library once via the constructor setting it as a class property and then accessing that via your other methods.

What you are doing might be easier for you to debug, but it's making your code less efficient and bloated.

If you use a good stepping debugger, all of this is moot anyway as you can see your objects in real time and set watches for them so you only see what you want.
#6

[eluser]jefc[/eluser]
Thanks for the reply.

Yeah I know it's better off in the constructor, and I know the other way is not ideal.

I think I must be doing something wrong, or at least in a less-than-clever way.

Things is I am building big objects and it can be difficult to keep one's bearings during development. An instance of 'A' might contain 5 of 'B', and 'B' may contain a couple of 'C's and each might have half a dozen or so instances of 'D'!! If 'D' has the CI object as a class property then when trying to view 'A' I'd be swamped by CI objects in my debug output!

I can write a little helper function for debug which cuts out the objects I don't want. But I can't feeling I'm doing something wrong...
#7

[eluser]Aken[/eluser]
Use __get() in your library and fetch from the CI object there.




Theme © iAndrew 2016 - Forum software by © MyBB