codeigniter - CI Event Calendar not showing current month data until clicking next/prev -
with code below ci calendar working fine view data database, when click next/prev. first time when calendar open default current month , doesn't show data database, cause in ulr after controller name there no year, month
parameter. can't find missed actually.
controller:
class my_calendar extends ci_controller { public function __construct() { parent::__construct(); $this->load->model('logindatamodel'); $this->load->model('my_calmodel'); } public function showcal($year=null, $month=null){ $user_data['userinfo'] = $this->logindatamodel->login_data(); $data['calendar']=$this->my_calmodel->generate($year,$month); $this->load->view('common/header', $user_data); $this->load->view('common/menu', $user_data); $this->load->view('my_calendar',$data); $this->load->view('common/footer'); } }
model:
class my_calmodel extends ci_model{ var $conf; function __construct() { parent::__construct(); $this->conf = array( 'start_day' => 'saturday', 'show_next_prev' => true, 'next_prev_url' => base_url().'my_calendar/showcal' ); } public function get_calendar_data($year, $month){ $query= $this->db->select('scheduledate, event_data') ->from('tbl_calendar') ->like('scheduledate',"$year-$month",'after') ->get(); $cal_data=array(); foreach($query->result() $row){ $index=ltrim(substr($row->scheduledate,8,2),'0'); $cal_data[$index]=$row->event_data; } return $cal_data; } public function generate($year, $month){ $this->load->library('calendar', $this->conf); $cal_data=$this->get_calendar_data($year, $month); return $this->calendar->generate($year,$month,$cal_data); } }
this bit old, original poster may have gotten fixed without coming tell forum. others stuck, here how fixed similar problem. controller should so:
public function showcal($year=null, $month=null){ if (!$year) { $year = date('y'); } if (!$month) { $month = date('m'); } $user_data['userinfo'] = $this->logindatamodel->login_data(); $data['calendar']=$this->my_calmodel->generate($year,$month); $this->load->view('common/header', $user_data); $this->load->view('common/menu', $user_data); $this->load->view('my_calendar',$data); $this->load->view('common/footer'); }
take note of initialisation month , year. reason because, since month , year passed arguments in function set null, if month , year aren't entered in url, browser assumes there no date. initialising month , year, current month , year passed controller , model, right data fetched.
enough of rambling. please original poster should check , accept.
yours truly.
Comments
Post a Comment