Welcome Guest, Not a member yet? Register   Sign In
How to Show Next/Previous Month Links for CodeIgniter 2.0.x Calendar Class Straight From the Library
#1

[eluser]lrussell810[/eluser]
I'm new to CodeIgniter, and came across an issue when trying to show the next/previous month links on a calendar that I wanted on my website. When I looked at the documentation for the Calendar Class in the CodeIgniter User Guide, it didn't explain very well how to do this properly. I'm posting this solution to help out anyone who may have a similar problem.

First, go to your Calendar class library `CodeIgniter_2.0.x/system/libaries/Calendar.php`. Open the file, and scroll down just below the beginning comments to where you see this section.

Code:
class CI_Calendar {

     var $CI;
     var $lang;
     var $local_time;
     var $template  = '';
     var $start_day  = 'sunday';
     var $month_type  = 'long';
     var $day_type  = 'long';
     var $show_next_prev = TRUE;
     var $next_prev_url = 'http://www.example.com/CONTROLLER/METHOD/';


Just like in the example above, remember to set the value of `var $show_next_prev` to `TRUE`, and in the value of `var $next_prev_url` to your website address (in this case we are using `http://www.example.com/`) with your CONTROLLER (this is the name of the controller to where you are loading the calendar library into) and METHOD (this is the method within the controller where you are loading the calendar library into).

The method section is where the User Guide dropped the ball. Remember, that if you have loaded the calendar library in the 'index' method within a controller named 'event_calendar', your value would be `http://www.example.com/event_calendar/index`. If it was loaded in a method named 'planner' within a controller named 'calendar' it your value would be `http://www.example.com/calendar/planner`.

After this is set up, go to the controller and method to where you are loading the calendar libary, and create a variable that is required to load specific segments into your view(s) where the calendar will be located. Here is an example:

Code:
$vars['calendar'] = $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));

This variable is important as it calls the necessary functions to show the previous/next links in your view where you're loading the calendar. So if you were to load it into a view named 'calendar_view' you would placed the following into your method.

Code:
$this->load->view('calendar_view', $vars);

I know that to a lot of you familiar with CodeIgniter may look at this, and think that what was typed above is totally obvious, but for someone who is brand new to web development (yours truly) it was a bit of a struggle to figured out. If you need to understand more about the confusion I'm talking about, please check out the CodeIgniter User Guide under Show Next/Previous Month Links in the Calendar Class section.




Theme © iAndrew 2016 - Forum software by © MyBB