我遇到Symphony在我的控制器中指定时没有注入Request对象的问题,我的代码如下:
的routing.yml:
user:
type: rest
resource: AppBundle\Controller\UserController
user_comments:
type: rest
parent: user
resource: AppBundle\Controller\UserCommentsController
和FosRest控制器
namespace AppBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
class UserCommentsController extends BaseRestController
{
public function postCommentAction(Request $request, $userId)
{
var_dump($request);
return $this->view($userId, 201);
}
我的应用程序根本没有对路由做出响应,但是当我从postCommentAction中删除Request $请求时,它按预期工作(但显然我无法访问Request对象)。
dev.log:
[2015-05-29 10:32:21] request.INFO: Matched route "post_user_comment" (parameters: "_controller": "AppBundle\Controller\UserCommentController::postCommentAction", "_format": "null", "userId": "a2fecac6-b7f6-4e00-8d03-989a9ee0973a", "_route": "post_user_comment") [] []
[2015-05-29 10:32:21] security.INFO: Attempting simple pre-authorization secured_area [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Nelmio\CorsBundle\EventListener\CorsListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\MimeTypeListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\FormatListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "FOS\RestBundle\EventListener\BodyListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". [] []
[2015-05-29 10:32:21] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
答案 0 :(得分:0)
很抱歉所有人 - 问题是由var_dump($ request)引起的 - 这是VM中隐藏的一个基本内存问题,考虑到PHP可以访问~512mb ram,令人印象深刻。