ews2001
ews2001

Reputation: 2187

FullCalendar Yii Module: actionList function in MainController.php

I'm trying to gain an understanding of how/where the $start and $end variables are being passed to the actionList function in the MainController.php script of the FullCalendar Yii Module:

http://www.yiiframework.com/extension/cal/

http://arshaw.com/fullcalendar/

public function actionList($start = 0, $end = 0)
{
    if ((Yii::app()->request->isAjaxRequest) and (Yii::app()->user->hasState('calUserId')) )
    {
        $criteria = new CDbCriteria(array(
                    'condition' => 'user_id=:user_id',
                    'params'=>array(':user_id'=> Yii::app()->user->getState('calUserId')),
                ));
        $criteria->addBetweenCondition('start', $start, $end);
        $events = Event::model()->findAll($criteria);
        echo CJSON::encode($events);
        Yii::app()->end();
    }
}

Does this come from the fullcalendar.min.js script? The only place it seems to be called is in eventCal.js:

var defaultCalendarOptions = {
        events: params.baseUrl+'list',

Are variables ever passed in using the Yii module or are they always $start=0,$end=0? If they are passed in, please explain how...

Upvotes: 1

Views: 899

Answers (1)

Grampa
Grampa

Reputation: 1643

The $start and $end variables are actually $_GET parameters that are passed to the actionList method. The Yii framework often does this - if an action method has parameters, it looks for $_GET parameters of the same name and passes those instead.

You made a good assumption that the events: params.baseUrl+'list' line is used for this, but the actual piece of code that sends the GET request is buried deep inside the fullcalendar.js file:

$.ajax($.extend({}, ajaxDefaults, source, {
    data: data,
    ...

In this code, source is the events parameter from above, which gets passed to the actual fullcalendar script and data is an array with the start and end parameters. You can find the full source of the script here. The extension you're using only has the minified version.

Upvotes: 1

Related Questions