Welcome Guest, Not a member yet? Register   Sign In
Instantiate Multiple Calendars
#1

[eluser]edwa5823[/eluser]
I am having trouble wrapping my brain around this problem and would like some assistance if at all possible.

I have just reached the first point where I need to instantiate a class more than once inside of a controller (using the calendar class), but I am not sure how to do that. I am just now learning how OOP really works, so I am afraid it is my ignorance and not a limitation of the framework--would someone be nice enough to point me in the right direction?

I am currently doing this:

Code:
$prefs = array (
            'start_day'    => 'saturday',
            'month_type'   => 'long',
            'day_type'     => 'long',
            'show_next_prev'  => TRUE,
            'next_prev_url'   => 'http://mydomain/index.php/events/calendar/',
        );
        $this->load->library('calendar', $prefs);
and then echoing the calendar in a view.

Now the problem is that I want to have one MAIN calendar that takes the above set of $prefs and then have three other calendars on the page with a different set of prefs. This would require a new instantiation of calendar.

Thanks in advance!!
#2

[eluser]elvix[/eluser]
load the library once, then you have access to all its functions. Set your prefs for each calendar, following each with the generate function (per user guide). you're passing in variables to a function, that's all. you don't need to instantiate the class again.

as long as you reset your prefs and regenerate, you should be fine. there's really nothing to it: just lather, rinse, repeat. Smile
#3

[eluser]edwa5823[/eluser]
I appreciate the help, it has helped me realize one flaw in my thinking thus far! However, I am still having bit of a problem with your response.. The $prefs array is actually passed into the loading of the library and not into a function:

Code:
$this->load->library('calendar', $prefs);

Once that calendar is loaded I would then have to RE-LOAD that library with a new set of $prefs to get the result I need. I hope I didn't misunderstand your reply, but is it possible to load a library twice, once with new values? When I try to load twice the first instance overrides the new one or throws an error (depending on where I place the loader).

Thanks again for the help, CI is great--I just want to understand it to use it effectively!
#4

[eluser]Unknown[/eluser]
If I understand correctly, you want to have more than one calendar on the same page. This is how I do it: In each controller, load the calendar library:
Code:
$this->CI->load->library('calendar');

For each calendar instance, use this:

Code:
$this->CI->calendar->initialize($prefs);

Where $prefs is your preferences array. Let me know if this solves your problem.




Theme © iAndrew 2016 - Forum software by © MyBB