php - 对 fullcalendar.io 使用普通 PHP 路由 (&) 和 symfony 路由 (/)

标签 php ajax symfony routes fullcalendar

我想在我的 Symfony2 项目中使用 fullcalendar.io。 Fullcalendar 发送此类获取事件数据的请求:

/myfeed.php?start=2013-12-01&end=2014-01-12&_=1386054751381

Symfony2 通常在 URl 中使用斜杠进行路由,仅存在此路由:

/myfeed/start=2013-12-01/end=2014-01-12/_=1386054751381

如何使用 Symfony2 的 Fullcalendar 功能?

这是我的测试 Controller :

<?php

namespace Chris\KfzBuchungBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;

class AjaxGetWeekController extends Controller
{
    public function indexAction(Request $request, $start)
    {

        $response = new Response(json_encode(array("title" => 'blub',"start" =>$start)));
        $response->headers->set('Content-Type', 'application/json');

        return $response;
    }
}

谢谢!

最佳答案

尽管 Symfony 路由通常设置不同,但您仍然可以非常轻松地检索查询字符串参数。请参阅以下内容:

http://symfony.com/doc/current/quick_tour/the_controller.html#getting-information-from-the-request

所以在你的 Controller 中你所要做的就是:

$start      = $request->query->get('start');
$end        = $request->query->get('start');
$timestamp  = $request->query->get('_');

我鼓励您阅读 Symfony 文档,因为它非常详尽,包含许多示例。此外,这个问题已经在 StackOverflow 上得到了解答,这里还有更多示例:How to get the request parameters in symfony2

关于php - 对 fullcalendar.io 使用普通 PHP 路由 (&) 和 symfony 路由 (/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27472592/

相关文章:

php - Magento 如何通过选项 ID 获取属性值?

php - 如何在php消息系统中设置已读未读标志

php - 将时间转换为总小时数并使用 php 从 mysql 数据计算

javascript - 通过JS AJAX调用调用Rails Controller 数据

php - 在 Highcharts 中从 PHP 加载 JSON 编码数据时,条形图不显示

symfony - 在 Symfony 上使用魔法方法进行路由

php - 在数据库中以月/日/年格式按名称搜索月份

javascript - Lucee/AJAX/CFARGUMENT 失败

mysql - 选择最后一个事件类型为 X 的所有用户

symfony - 检查实体属性是否存在