Yii2完整日历AjaxEvents无法正常工作

时间:2015-11-25 23:06:50

标签: yii2 yii2-advanced-app yii2-basic-app

大家好我在我的项目中使用this extension,我遇到ajaxEvents的问题,我想知道我在这里做错了什么?这是我的视图文件和控制器操作代码

<div class="container">
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    <?= yii2fullcalendar::widget([
        'events' => $events,
        'options' => [
            'language' => 'en',
            'eventLimit' => 2,
        ],
        'ajaxEvents' => \yii\helpers\Url::to(['/jsoncalendar'])
    ]);
    ?>
        </div>
    </div>

</div>

这是控制器代码

 public function actionJsoncalendar($start=NULL,$end=NULL,$_=NULL){

    \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

    $times = Event::find()->where(1)->all();

    $events = array();

    foreach ($times AS $time){
        //Testing
        $Event = new \yii2fullcalendar\models\Event();
        $Event->id = $time->id;
        $Event->title = $time->title;
        $Event->start = $time->start_time;
        $Event->end = $time->end_time;
        $events[] = $Event;
    }

    return $events;
}

也尝试使用eventLimit,但那不起作用

1 个答案:

答案 0 :(得分:1)

我正在使用相同的扩展,我发现(至少在我的项目中)ajaxEvents应该返回一个编码的JSON数组。试着回复:

return json_encode($events);

并删除此行:

\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;