0

アプリケーションでイベントカレンダーとしてjquery拡張機能を使用しようとしています。私は最初にコア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

$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 に答える