Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Action Class Reference
Inheritance diagram for Action:
AbstractAction ActionInterface Payment AbstractAction GetNonce AbstractAction Index View Index Product Compare Synchronize Index Result Index Save Create DelegateCreate Action Cart UpdateItemQty Index Index RemoveItem UpdateItemQty DefaultNoRoute Index Index View Index NoCookies AbstractAccount Address Login Logout Review Load SwitchAction Products Download ActionFake ActionStub Index Index PlaceOrder Access Request Address Success Manage Subscriber Block Agreement Start AbstractExpress Cancel ReturnAction Index Payflow Start RequestSecureToken Response Index Add Customer Product Index Feed Index PrintAction PrintCreditmemo PrintInvoice PrintShipment DownloadCustomOption Form History Suggest Popular Product Popup Handler Redirect SwitchAction Index Media Index Render CardsManagement Index Allcart Cart Index

Public Member Functions

 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Protected Member Functions

 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Additional Inherited Members

- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 

Detailed Description

Extend from this class to create actions controllers in frontend area of your application. It contains standard action behavior (event dispatching, flag checks) Action classes that do not extend from this class will lose this behavior and might not function correctly

TODO: Remove this class. Allow implementation of Action Controllers by just implementing Action Interface.

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.NumberOfChildren)

Since
100.0.2

Definition at line 25 of file Action.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context)
Parameters
Context$context

Definition at line 73 of file Action.php.

74  {
75  parent::__construct($context);
76  $this->_objectManager = $context->getObjectManager();
77  $this->_eventManager = $context->getEventManager();
78  $this->_url = $context->getUrl();
79  $this->_actionFlag = $context->getActionFlag();
80  $this->_redirect = $context->getRedirect();
81  $this->_view = $context->getView();
82  $this->messageManager = $context->getMessageManager();
83  }
_redirect($path, $arguments=[])
Definition: Action.php:167

Member Function Documentation

◆ _forward()

_forward (   $action,
  $controller = null,
  $module = null,
array  $params = null 
)
protected

Throw control to different action (control and module if was specified).

Parameters
string$action
string | null$controller
string | null$module
array | null$params
Returns
void

Definition at line 137 of file Action.php.

138  {
139  $request = $this->getRequest();
140 
141  $request->initForward();
142 
143  if (isset($params)) {
144  $request->setParams($params);
145  }
146 
147  if (isset($controller)) {
148  $request->setControllerName($controller);
149 
150  // Module should only be reset if controller has been specified
151  if (isset($module)) {
152  $request->setModuleName($module);
153  }
154  }
155 
156  $request->setActionName($action);
157  $request->setDispatched(false);
158  }
$controller
Definition: info.phtml:14
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _redirect()

_redirect (   $path,
  $arguments = [] 
)
protected

Set redirect into response

Parameters
string$path
array$arguments
Returns
ResponseInterface

Definition at line 167 of file Action.php.

168  {
169  $this->_redirect->redirect($this->getResponse(), $path, $arguments);
170  return $this->getResponse();
171  }
_redirect($path, $arguments=[])
Definition: Action.php:167
$arguments

◆ dispatch()

dispatch ( RequestInterface  $request)

Dispatch request

Parameters
RequestInterface$request
Returns
ResponseInterface
Exceptions
NotFoundException

Definition at line 92 of file Action.php.

93  {
94  $this->_request = $request;
95  $profilerKey = 'CONTROLLER_ACTION:' . $request->getFullActionName();
96  $eventParameters = ['controller_action' => $this, 'request' => $request];
97  $this->_eventManager->dispatch('controller_action_predispatch', $eventParameters);
98  $this->_eventManager->dispatch('controller_action_predispatch_' . $request->getRouteName(), $eventParameters);
99  $this->_eventManager->dispatch(
100  'controller_action_predispatch_' . $request->getFullActionName(),
101  $eventParameters
102  );
103  \Magento\Framework\Profiler::start($profilerKey);
104 
105  $result = null;
106  if ($request->isDispatched() && !$this->_actionFlag->get('', self::FLAG_NO_DISPATCH)) {
107  \Magento\Framework\Profiler::start('action_body');
108  $result = $this->execute();
109  \Magento\Framework\Profiler::start('postdispatch');
110  if (!$this->_actionFlag->get('', self::FLAG_NO_POST_DISPATCH)) {
111  $this->_eventManager->dispatch(
112  'controller_action_postdispatch_' . $request->getFullActionName(),
113  $eventParameters
114  );
115  $this->_eventManager->dispatch(
116  'controller_action_postdispatch_' . $request->getRouteName(),
117  $eventParameters
118  );
119  $this->_eventManager->dispatch('controller_action_postdispatch', $eventParameters);
120  }
121  \Magento\Framework\Profiler::stop('postdispatch');
122  \Magento\Framework\Profiler::stop('action_body');
123  }
124  \Magento\Framework\Profiler::stop($profilerKey);
125  return $result ?: $this->_response;
126  }

◆ getActionFlag()

getActionFlag ( )
Returns
\Magento\Framework\App\ActionFlag

Definition at line 176 of file Action.php.

177  {
178  return $this->_actionFlag;
179  }

Field Documentation

◆ $_actionFlag

$_actionFlag
protected

Definition at line 48 of file Action.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 43 of file Action.php.

◆ $_objectManager

$_objectManager
protected

Definition at line 30 of file Action.php.

◆ $_redirect

$_redirect
protected

Definition at line 53 of file Action.php.

◆ $_sessionNamespace

$_sessionNamespace
protected

Definition at line 38 of file Action.php.

◆ $_url

$_url
protected

Definition at line 63 of file Action.php.

◆ $_view

$_view
protected

Definition at line 58 of file Action.php.

◆ $messageManager

$messageManager
protected

Definition at line 68 of file Action.php.


The documentation for this class was generated from the following file: