2

Hi guys i am using a Jquery plugin for displaying events in calendar and i can see the plugin calendar on my view file just the problem is that i can not create valid json format file for the plugin

This is the format given in the plugin demo page

 <?php
header('Content-type: text/json');
echo '[';
$separator = "";
$days = 16;
echo '  { "date": "1314579600000", "type": "meeting", "title": "Test Last Year" },';
echo '  { "date": "1377738000000", "type": "meeting", "title": "Test Next Year"},';
for ($i = 1 ; $i < $days; $i= 1 + $i * 2) {
  echo $separator;
  $initTime = (intval(microtime(true))*1000) + (86400000 * ($i-($days/2)));
  echo '    { "date": "'; echo $initTime; echo '", "type": "meeting", "title": "Project '; echo $i; echo ' meeting",   },';
  echo '    { "date": "'; echo $initTime+3600000; echo '", "type": "demo", "title": "Project '; echo $i; echo ' demo" },';

  $separator = ",";
 }
  echo ']';
?>

What should be my controller code to display the data. I tried the format in the answer below but it still doesnt display the data properly.

I think something is wrong in the json format i am receiving on frontend. First image is my localhost where i am receiving data and the second one is plugin demo and array format is a bit different i guess and thats the problem

enter image description here

enter image description here

1 Answer 1

1

Why don't you create a controller and put inside an 'event' action?

<?php
namespace app\controllers;


class SiteController extends Controller
{
    public function actionEvent()
    {
       /* Input parameters */
       $limit = \Yii::$app->request->get('limit');
       $year = \Yii::$app->request->get('year');
       $month = \Yii::$app->request->get('month');
       $day = \Yii::$app->request->get('day');

       /* Fill data */
       $data = [];
       $data[] = [ 'date' => '1314579600000', 'type' => 'meeting', 'title' => 'Test Last Year' ]; 

       /*
       ...
       ... other data ...
       ...
       */

        /* Prepare the content output*/
        \Yii::$app->response->format = 'json';
        echo \yii\helpers\Json::encode($data);
    }
}

and finally call the action:

$("#eventCalendarNewWindow").eventCalendar({
        eventsjson: "<?php echo \yii\helpers\Url::to(['site/event']) ?>",
        openEventInNewWindow: true,
        showDescription: true // also it can be false
});
Sign up to request clarification or add additional context in comments.

6 Comments

i tried that before but the problem with that was i could get the response back in the browser fine but it doesnt display anything on the event date. It still displays there are no events on that date thats why i tried this format.
maybe is description field (now missing in the code) mandatory?
@ FabrizioCaldarelli no thats not it. I have tried without Description and setting it to false.
have you checked with firebug if there is some javascript error?
i checked with google chrome and no error and also checked with firebug console is clear no error or warning
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.