Welcome Guest, Not a member yet? Register   Sign In
Problem working out how to make $CI->$variable work

[eluser]J Maxwell[/eluser]
I have searched a bit for this, but strugging to work out how to achieve what I want.

I am querying a database, then dynamically loading assets based on the results of the query.

However, I need to do something like this:

foreach ($w as $widget) :

/* i've written an extension to the CI_Loader that enables me to add widgets.
* It loads them into $this->widget_name however, because i need to access them during a
* foreach loop, then I can't manually enter the name of the widget in order to use it, it needs
* to come from the variable


The problem with this is it keeps throwing member function on non-object errors. How do I refer to the widget I just created without being able to type the name in?



Does your $this->load->widget() method assign the new class to the CI object?

Something simple as this would do it:
$CI =& get instance();
$CI->$widget = new $widget();

[eluser]J Maxwell[/eluser]
Hey, thanks for that, I was sure there was a pretty simple explanation and I'd spent long enough staring blankly at the screen that I wasn't going to get it!

Problem fixed, many thanks.


Theme © iAndrew 2016 - Forum software by © MyBB