Note that the action name must start with a lower case letter and is case sensitive.
public setControllerActionName ( string $actionName ) : void | ||
$actionName | string | Name of the action to execute by the controller |
리턴 | void |
/** * Determines the action method and assures that the method exists. * * @return string The action method name * @throws NoSuchActionException if the action specified in the request object does not exist (and if there's no default action either). */ protected function resolveActionMethodName() { if ($this->request->getControllerActionName() === 'index') { $actionName = 'index'; switch ($this->request->getHttpRequest()->getMethod()) { case 'HEAD': case 'GET': $actionName = $this->request->hasArgument($this->resourceArgumentName) ? 'show' : 'list'; break; case 'POST': $actionName = 'create'; break; case 'PUT': if (!$this->request->hasArgument($this->resourceArgumentName)) { $this->throwStatus(400, null, 'No resource specified'); } $actionName = 'update'; break; case 'DELETE': if (!$this->request->hasArgument($this->resourceArgumentName)) { $this->throwStatus(400, null, 'No resource specified'); } $actionName = 'delete'; break; } $this->request->setControllerActionName($actionName); } return parent::resolveActionMethodName(); }
/** * @test */ public function actionRequestStripsParentHttpRequest() { $httpRequest = Request::create(new Uri('http://neos.io')); $actionRequest = new ActionRequest($httpRequest); $actionRequest->setControllerActionName('foo'); $serializedActionRequest = serialize($actionRequest); /* @var $unserializedActionRequest ActionRequest */ $unserializedActionRequest = unserialize($serializedActionRequest); $this->assertNull($unserializedActionRequest->getParentRequest(), 'Parent HTTP request should be NULL after deserialization'); $this->assertSame('foo', $unserializedActionRequest->getControllerActionName()); }
/** * @param array $module * @return mixed * @throws DisabledModuleException */ public function indexAction(array $module) { $moduleRequest = new ActionRequest($this->request); $moduleRequest->setArgumentNamespace('moduleArguments'); $moduleRequest->setControllerObjectName($module['controller']); $moduleRequest->setControllerActionName($module['action']); if (isset($module['format'])) { $moduleRequest->setFormat($module['format']); } if ($this->request->hasArgument($moduleRequest->getArgumentNamespace()) === true && is_array($this->request->getArgument($moduleRequest->getArgumentNamespace()))) { $moduleRequest->setArguments($this->request->getArgument($moduleRequest->getArgumentNamespace())); } foreach ($this->request->getPluginArguments() as $argumentNamespace => $argument) { $moduleRequest->setArgument('--' . $argumentNamespace, $argument); } $modules = explode('/', $module['module']); $moduleConfiguration = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $modules)); $moduleConfiguration['path'] = $module['module']; if (!$this->menuHelper->isModuleEnabled($moduleConfiguration['path'])) { throw new DisabledModuleException(sprintf('The module "%s" is disabled. You can enable it with the "enabled" flag in Settings.yaml.', $module['module']), 1437148922); } $moduleBreadcrumb = array(); $path = array(); foreach ($modules as $moduleIdentifier) { array_push($path, $moduleIdentifier); $config = Arrays::getValueByPath($this->settings['modules'], implode('.submodules.', $path)); $moduleBreadcrumb[implode('/', $path)] = $config; } $moduleRequest->setArgument('__moduleConfiguration', $moduleConfiguration); $moduleResponse = new Response($this->response); $this->dispatcher->dispatch($moduleRequest, $moduleResponse); if ($moduleResponse->hasHeader('Location')) { $this->redirectToUri($moduleResponse->getHeader('Location'), 0, $moduleResponse->getStatusCode()); } elseif ($moduleRequest->getFormat() !== 'html') { $mediaType = MediaTypes::getMediaTypeFromFilename('file.' . $moduleRequest->getFormat()); if ($mediaType !== 'application/octet-stream') { $this->controllerContext->getResponse()->setHeader('Content-Type', $mediaType); } return $moduleResponse->getContent(); } else { $user = $this->partyService->getAssignedPartyOfAccount($this->securityContext->getAccount()); $sites = $this->menuHelper->buildSiteList($this->controllerContext); $this->view->assignMultiple(array('moduleClass' => implode('-', $modules), 'moduleContents' => $moduleResponse->getContent(), 'title' => $moduleRequest->hasArgument('title') ? $moduleRequest->getArgument('title') : $moduleConfiguration['label'], 'rootModule' => array_shift($modules), 'submodule' => array_shift($modules), 'moduleConfiguration' => $moduleConfiguration, 'moduleBreadcrumb' => $moduleBreadcrumb, 'user' => $user, 'modules' => $this->menuHelper->buildModuleList($this->controllerContext), 'sites' => $sites)); } }
/** * @test * @param mixed $invalidActionName * @dataProvider invalidActionNames * @expectedException \Neos\Flow\Mvc\Exception\InvalidActionNameException */ public function setControllerActionNameThrowsExceptionOnInvalidActionNames($invalidActionName) { $this->actionRequest->setControllerActionName($invalidActionName); }
/** * Pass the arguments of the widget to the sub request. * * @param ActionRequest $subRequest * @return void */ private function passArgumentsToSubRequest(ActionRequest $subRequest) { $arguments = $this->controllerContext->getRequest()->getPluginArguments(); $widgetIdentifier = $this->widgetContext->getWidgetIdentifier(); $controllerActionName = 'index'; if (isset($arguments[$widgetIdentifier])) { if (isset($arguments[$widgetIdentifier]['@action'])) { $controllerActionName = $arguments[$widgetIdentifier]['@action']; unset($arguments[$widgetIdentifier]['@action']); } $subRequest->setArguments($arguments[$widgetIdentifier]); } if ($subRequest->getControllerActionName() === null) { $subRequest->setControllerActionName($controllerActionName); } }
/** * Set the default controller and action names if none has been specified. * * @param ActionRequest $actionRequest * @return void */ protected function setDefaultControllerAndActionNameIfNoneSpecified(ActionRequest $actionRequest) { if ($actionRequest->getControllerName() === null) { $actionRequest->setControllerName('Standard'); } if ($actionRequest->getControllerActionName() === null) { $actionRequest->setControllerActionName('index'); } }