Creating a calendar from database entries - El Forum - 03-10-2014
[eluser]Skoobi[/eluser]
Hi im currently in the process of building an events calendar for my site but im having a bit of an issue.
Heres my controller
Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class App_cal extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->helper('date');
$this->load->helper('form');
$this->load->model('app_cal_model');
}
public function index(){
redirect('admin/app_cal/show');
}
public function show(){
$prefs = array(
'start_day' => 'monday',
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => 'app_cal/show/'
);
$this->load->library('calendar', $prefs);
if ($this->uri->segment(4)) {
$year= $this->uri->segment(3);
$month = $this->uri->segment(4);
} else {
$year = date("Y", time());
$month = date("m", time());
}
$this->load->model('App_cal_model');
$appointments = $this->App_cal_model->get_appointments($year, $month);
$data = array();
foreach ($appointments->result() as $row) {
$data[(int)date("d",$row->app_date)] = $row->app_url;
}
$data['cal_data'] = $this->calendar->generate($year,$month, $data);
// Load view
$this->data['subview'] = 'admin/app_cal/show';
$this->load->view('admin/_layout_main', $this->data);
}
}
/* End of file app_cal.php */
/* Location: ./application/controllers/admin/app_cal.php */
But im getting this error.
Fatal error: Call to a member function result() on a non-object in /var/sites/c/my_site/application/controllers/admin/app_cal.php on line 43
Any ideas??
Cheers
Chris
Creating a calendar from database entries - El Forum - 03-10-2014
[eluser]Skoobi[/eluser]
Ok Sorted
It turned out i had db_debug False which once sorted i found it was a db error...
Creating a calendar from database entries - El Forum - 03-10-2014
[eluser]Skoobi[/eluser]
Ok next issue is trying to get info to the calendar... But the linking to next month is giving me this error
A PHP Error was encountered
Severity: Warning
Message: mktime() expects parameter 6 to be long, string given
Filename: libraries/Calendar.php
Line Number: 129
Creating a calendar from database entries - El Forum - 03-10-2014
[eluser]Ckirk[/eluser]
Code: $month = $this->uri->segment(4);
That will return $month as a string. you need to convert it to an integer.
Creating a calendar from database entries - El Forum - 03-11-2014
[eluser]Skoobi[/eluser]
Cheers for the reply... After reading your reply i realised what was wrong :/ i was catching the wrong segments!!!!
Heres my controller for the show calendar. The issue i had was :
Code: if ($this->uri->segment(5)) {
$year= $this->uri->segment(4);
$month = $this->uri->segment(5);
}
The segments were 4,3,4 which was the admin/app_cal/show and not the segments after that for the date.
The next issue im getting is its linking forwards to the next month on the calendar but when i try to go back the uri adds another year so its /admin/app_cal/show/2014/2014/04
Code: public function show(){
if ($this->uri->segment(5)) {
$year= $this->uri->segment(4);
$month = $this->uri->segment(5);
} else {
$year = date("Y", time());
$month = date("m", time());
}
$tpl = '{table_open}<table border="1" cellpadding="15"cellspacing="1">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><a href="{previous_url}"><<</a></th>{/heading_previous_cell}
{heading_title_cell}<th colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th><a 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}<td>{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}'.anchor('app_cal/create/'.$year.'/'.$month.'/{day}', '+').' <a href="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight">'.anchor('app_cal/create/'.$year.'/'.$month.'/{day}', '+').'<a href="{content}">{day}</a></div>{/cal_cell_content_today}
{cal_cell_no_content}'.anchor('app_cal/create/'.$year.'/'.$month.'/{day}', '+').' {day}{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="highlight">'.anchor('app_cal/create/'.$year.'/'.$month.'/{day}', '+').'{day}</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}';
$prefs = array(
'start_day' => 'monday',
'month_type' => 'long',
'day_type' => 'short',
'show_next_prev' => TRUE,
'next_prev_url' => '',
'template' => $tpl,
);
$this->load->library('calendar', $prefs);
$appointments = $this->App_cal_model->get_appointments($year, $month);
$data = array();
foreach ($appointments->result() as $row) {
$data[(int)date("d",$row->app_date)] = $row->app_url;
}
$this->data['cal_data'] = $this->calendar->generate($year,$month, $data);
// Load view
$this->data['subview'] = 'admin/app_cal/show';
$this->load->view('admin/_layout_main', $this->data);
}
Any ideas why this is???
Cheers
Chris
|