Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function __construct(Request $request){
- $this->startGameSession($request);
- }
- Catchable Fatal Error: Argument 1 passed to MyController::__construct() must be an instance of SymfonyComponentHttpFoundationRequest, none given...
- namespace AppBundleController;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentHttpFoundationRequestStack;
- class ServiceController extends Controller
- {
- public function __construct(RequestStack $requestStack)
- {
- //do something with $requestStack->getCurrentRequest();
- }
- }
- # app/config/services.yml
- services:
- service_controller:
- class: AppBundleControllerServiceController
- arguments: ['@request_stack']
- # app/config/routing.yml
- index:
- path: /index
- defaults: { _controller: service_controller:indexAction }
- use SymfonyComponentHttpFoundationRequest;
- namespace SymfonyComponentHttpKernelControllerControllerResolver;
- ...
- public function getController(Request $request)
- {
- if (!$controller = $request->attributes->get('_controller')) {
- if (null !== $this->logger) {
- $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.');
- }
- return false;
- }
- if (is_array($controller)) {
- return $controller;
- }
- if (is_object($controller)) {
- if (method_exists($controller, '__invoke')) {
- return $controller;
- }
- throw new InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo()));
- }
- if (false === strpos($controller, ':')) {
- if (method_exists($controller, '__invoke')) {
- return $this->instantiateController($controller);
- } elseif (function_exists($controller)) {
- return $controller;
- }
- }
- $callable = $this->createController($controller);
- if (!is_callable($callable)) {
- throw new InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($callable)));
- }
- return $callable;
- }
- namespace AppBundleController;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentHttpFoundationRequestStack;
- class MyController extends Controller
- {
- public function __construct(RequestStack $requestStack)
- {
- $request = $requestStack->getCurrentRequest();
- //do something with the $request
- }
- }
Add Comment
Please, Sign In to add comment