0

我正在尝试在我的应用程序中使用 jquery 扩展作为事件日历。我先用core php试了一下,效果很好。现在我想在我的 symfony2 应用程序中使用它,但我无法在我的 twig 文件中显示它。这是我用来渲染的代码,但我不确定我在哪里做错了。

控制器

public function studentCalendarAction()
{
  $year = date('Y');
  $month = date('m');
  $response = new Response(json_encode(array(
        array(
                'id' => 111,
                'title' => "Event1",
                'start' => "$year-$month-10",
                'url' => "http://yahoo.com/"
        ),
  )));
  $response->headers->set('Content-Type', 'application/json');
  return $this->render('CollegeStudentBundle:StudentAttendance:calendar.html.twig',array('response'=>$response));
}

路由器

CollegeStudentBundle_attendance_calendar:
    pattern:  /student/attendance/calendar
    defaults: { _controller: CollegeStudentBundle:StudentAttendance:studentCalendar }
    requirements:
        _method:  GET|POST

枝条

    <script type='text/javascript'>

                $(document).ready(function() {

                $('#calendar').fullCalendar({

                    editable: true,

                    events: "../../student/attendance/calendar",

                    eventDrop: function(event, delta) {
                        alert(event.title + ' was moved ' + delta + ' days\n' +
                            '(should probably update your database)');
                    },

                    loading: function(bool) {
                        if (bool) $('#loading').show();
                        else $('#loading').hide();
                    }

                });

            });

    </script>


</head>

<body>
    <div id='calendar'></div>
</body>

即使我试图让我Router喜欢这个

CollegeStudentBundle_attendance_calendar:
    pattern:  /student/attendance/calendar
    defaults: { _controller: CollegeStudentBundle:StudentAttendance:studentCalendar, _format: json }
    requirements: { _format: (xml|json), _method: GET }  

但这显示了树枝文件的代码。

4

1 回答 1

3

只需返回 created $response,而不是呈现的响应。

编辑:你的修改studentCalendarAction是,

public function studentCalendarAction()
{
  $year = date('Y');
  $month = date('m');

  $jsonData = json_encode(array(
        array(
                'id' => 111,
                'title' => "Event1",
                'start' => "$year-$month-10",
                'url' => "http://yahoo.com/"
        ),
  ));

  $headers = array(
        'Content-Type' => 'application/json'
  );

  $response = new Response($jsonData, 200, $headers);
  return $response;
}

另外我认为树枝文件是从不同的路线呈现的,而不是CollegeStudentBundle_attendance_calendar路线。

于 2012-04-15T07:49:07.453 回答