Symfony 请求对象未注入 FosRest 嵌套控制器中
Symfony Request Object not being Injected in FosRest nested controller
我遇到一个问题,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 时,它按预期工作(但显然我无权访问 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". [] []
抱歉大家 - 问题是由 var_dump($request) 引起的 - 一个隐藏在 VM 中的基本内存问题,令人印象深刻考虑到 PHP 可以访问 ~512mb ram。
我遇到一个问题,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 时,它按预期工作(但显然我无权访问 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". [] []
抱歉大家 - 问题是由 var_dump($request) 引起的 - 一个隐藏在 VM 中的基本内存问题,令人印象深刻考虑到 PHP 可以访问 ~512mb ram。