Denver
Denver

Reputation: 61

CakePHP Calendar

I am new to CakePHP, and would like to create a calendar using this framework. I am having a difficult time, and am wondering if there is a tutorial or guide on how to create a simple calendar using CakePHP?

Upvotes: 6

Views: 5065

Answers (3)

Akshay Sharma
Akshay Sharma

Reputation: 1112

  1. Download js or css file http://fullcalendar.io/download/
  2. Controller code

    function feeds(){
        $this->layout   =   'ajax';
        if(isset($this->params->query['start'])){
            $start = $this->params->query['start'];
        }
        if(isset($this->params->query['end'])){
            $end = $this->params->query['end'];
        }   
        $events     =   $this->{$this->modelClass}->find('all',array('conditions' => array('startdate >=' => $start,'enddate  $end)));
        $data = '';
        foreach($events as $res ){          
            $data[] = array(
                    'id' => $res[$this->modelClass]['id'],
                    'title'=> $res[$this->modelClass]['title'],
                    'start'=> Date('Y-m-d H:m',$res[$this->modelClass]['startdate']),
                    'end' => Date('Y-m-d H:m',$res[$this->modelClass]['enddate']),
                    'start_time' => Date('h:ia',$res[$this->modelClass]['startdate']),
                    'end_time' => Date('h:ia',$res[$this->modelClass]['enddate'])                   
            );
        }
        echo json_encode($data);
        exit;
    }

  1. View file
    Add this in .ctp file


    <div class="" id="calendar_div">

Js code for view file

$('#calendar_div').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'agendaDay,agendaWeek,month'
    },      
    defaultView: 'month',
    events: '<?php echo $this->Html->url(array('action' => 'feeds')); ?>',
    selectable: true,
    selectHelper: true          
});

Upvotes: 0

Diego Fu
Diego Fu

Reputation: 420

https://github.com/silasmontgomery/CakePHP-Full-Calendar-Plugin

This is a calendar plugin for cakephp via fullCalendar

Upvotes: 1

Mika
Mika

Reputation: 1539

Here are two links: LINK1(calendar helper) and LINK2 to a implementation of FullCalendar. I did not try both of them...

Upvotes: 4

Related Questions