[eluser]lrussell810[/eluser]
I’m trying to use the CodeIgniter Calendar Class to activate the next/previous month links in my event calendar. I’m having trouble though, as it keeps coming up with a 404 error every time that I try and use the links. The URI looks correct, and I’ve tried to go off of the user manual, but the calendar class guide looks like it’s from another version and not 2.0.2. Any suggestions on how to get this working would be great. Thank you very much!
[eluser]toymachiner62[/eluser]
Please post some code so we can help you. I'm guessing your calendar loads correctly, but when you click the next/prev button it does not?
[eluser]lrussell810[/eluser]
Here is my controller
Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Planner extends CI_Controller {
function index()
{
$temp['template'] = '
{table_open}<table class="planner">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th>< href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th>< href="{next_url}">>></a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<th class="day_header">{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_content}<span class="day_listing">{day}</span> • {content} {/cal_cell_content}
{cal_cell_content_today}<div class="today"><span class="day_listing">{day}</span>• {content}</div>{/cal_cell_content_today}
{cal_cell_no_content}<span class="day_listing">{day}</span> {/cal_cell_no_content}
{cal_cell_no_content_today}<div class="today"><span class="day_listing">{day}</span></div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
$data = array(
3 => 'Pray 3X Daily',
7 => 'Read 1 Chapter of Romans',
13 => 'Do 20 Minute Workout',
26 => 'Study CodeIgniter Libraries'
);
$this->load->library('calendar', $temp);
$vars['calendar'] = $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4), $data);
$this->load->view('plannerview', $vars);
}
}
/* End of file planner.php */
/* Location: ./application/controllers/calendar.php */
[eluser]lrussell810[/eluser]
Here is what is in my calendar library.
Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://ellislab.com/codeigniter/user-guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter Calendar Class
*
* This class enables the creation of calendars
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author ExpressionEngine Dev Team
* @link http://ellislab.com/codeigniter/user-guide/libraries/calendar.html
*/
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://discipleshipplanning.com/planner/';
[eluser]toymachiner62[/eluser]
The documentation does suck for figuring out how to generate the calendar class prev/next links correctly, but try something like this:
Code: // the way that functions with variable's generally work in CI is that the first variable is the same as
// segment(3), the next one the same as segment(4), etc. By setting them equal to false as I did says that
// "if there is no segment(3), set $year to false, and if there is not segment(4), set $month to false".
function index($year = false, $month = false)
{
// if &year; and $month are false, set them using PHP's native date function.
if( $year === FALSE ) $year = date( 'Y' );
if( $month === FALSE ) $month = date( 'm' );
$temp['template'] = '
{table_open}<table class="planner">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th>< href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th>< href="{next_url}">>></a></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<th class="day_header">{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr>{/cal_row_start}
{cal_cell_start}<td>{/cal_cell_start}
{cal_cell_content}<span class="day_listing">{day}</span> • {content} {/cal_cell_content}
{cal_cell_content_today}<div class="today"><span class="day_listing">{day}</span>• {content}</div>{/cal_cell_content_today}
{cal_cell_no_content}<span class="day_listing">{day}</span> {/cal_cell_no_content}
{cal_cell_no_content_today}<div class="today"><span class="day_listing">{day}</span></div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
$data = array(
3 => 'Pray 3X Daily',
7 => 'Read 1 Chapter of Romans',
13 => 'Do 20 Minute Workout',
26 => 'Study CodeIgniter Libraries'
);
$this->load->library('calendar', $temp);
// pass the $year and $month into the generate function
$vars['calendar'] = $this->calendar->generate($year, $month, $data);
$this->load->view('plannerview', $vars);
}
[eluser]lrussell810[/eluser]
I'm still receiving a 404
[eluser]toymachiner62[/eluser]
Hmm. I've never set my pref's in the actual CI Calendar class. You should never need to modify the core classes. Try removing those and just adding the snippet below to the
Code: $temp = array (
'start_day' => 'sunday',
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => site_url('member/memberCalendar')
);
[eluser]lrussell810[/eluser]
Yeah, they're loaded into 2.0.2 and they work without me having to to that array you just posted. I went through though and removed them, placed in that array and everything. Still nothing. I'm sure it's something small, but EllisLab just needs to put up a clearer way of doing it in their user guide promptly.
[eluser]toymachiner62[/eluser]
That way should work. Are you sure you're reloading your page with NO year and month at first?
[eluser]lrussell810[/eluser]
Yeah no year and month is listed in the URI. Am I supposed to have the URL helper auto-loaded?
|