我想在我的 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/