Controller.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 0.2.9
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Controller;
  16. use Cake\Controller\Exception\MissingActionException;
  17. use Cake\Datasource\ModelAwareTrait;
  18. use Cake\Event\Event;
  19. use Cake\Event\EventDispatcherInterface;
  20. use Cake\Event\EventDispatcherTrait;
  21. use Cake\Event\EventListenerInterface;
  22. use Cake\Log\LogTrait;
  23. use Cake\Network\Request;
  24. use Cake\Network\Response;
  25. use Cake\ORM\Locator\LocatorAwareTrait;
  26. use Cake\Routing\RequestActionTrait;
  27. use Cake\Routing\Router;
  28. use Cake\Utility\MergeVariablesTrait;
  29. use Cake\View\ViewVarsTrait;
  30. use LogicException;
  31. use ReflectionException;
  32. use ReflectionMethod;
  33. use RuntimeException;
  34. /**
  35. * Application controller class for organization of business logic.
  36. * Provides basic functionality, such as rendering views inside layouts,
  37. * automatic model availability, redirection, callbacks, and more.
  38. *
  39. * Controllers should provide a number of 'action' methods. These are public
  40. * methods on a controller that are not inherited from `Controller`.
  41. * Each action serves as an endpoint for performing a specific action on a
  42. * resource or collection of resources. For example adding or editing a new
  43. * object, or listing a set of objects.
  44. *
  45. * You can access request parameters, using `$this->request`. The request object
  46. * contains all the POST, GET and FILES that were part of the request.
  47. *
  48. * After performing the required action, controllers are responsible for
  49. * creating a response. This usually takes the form of a generated `View`, or
  50. * possibly a redirection to another URL. In either case `$this->response`
  51. * allows you to manipulate all aspects of the response.
  52. *
  53. * Controllers are created by `Dispatcher` based on request parameters and
  54. * routing. By default controllers and actions use conventional names.
  55. * For example `/posts/index` maps to `PostsController::index()`. You can re-map
  56. * URLs using Router::connect() or RouterBuilder::connect().
  57. *
  58. * ### Life cycle callbacks
  59. *
  60. * CakePHP fires a number of life cycle callbacks during each request.
  61. * By implementing a method you can receive the related events. The available
  62. * callbacks are:
  63. *
  64. * - `beforeFilter(Event $event)`
  65. * Called before each action. This is a good place to do general logic that
  66. * applies to all actions.
  67. * - `beforeRender(Event $event)`
  68. * Called before the view is rendered.
  69. * - `beforeRedirect(Event $event, $url, Response $response)`
  70. * Called before a redirect is done.
  71. * - `afterFilter(Event $event)`
  72. * Called after each action is complete and after the view is rendered.
  73. *
  74. * @property \Cake\Controller\Component\AuthComponent $Auth
  75. * @property \Cake\Controller\Component\CookieComponent $Cookie
  76. * @property \Cake\Controller\Component\CsrfComponent $Csrf
  77. * @property \Cake\Controller\Component\FlashComponent $Flash
  78. * @property \Cake\Controller\Component\PaginatorComponent $Paginator
  79. * @property \Cake\Controller\Component\RequestHandlerComponent $RequestHandler
  80. * @property \Cake\Controller\Component\SecurityComponent $Security
  81. * @link http://book.cakephp.org/3.0/en/controllers.html
  82. */
  83. class Controller implements EventListenerInterface, EventDispatcherInterface
  84. {
  85. use EventDispatcherTrait;
  86. use LocatorAwareTrait;
  87. use LogTrait;
  88. use MergeVariablesTrait;
  89. use ModelAwareTrait;
  90. use RequestActionTrait;
  91. use ViewVarsTrait;
  92. /**
  93. * The name of this controller. Controller names are plural, named after the model they manipulate.
  94. *
  95. * Set automatically using conventions in Controller::__construct().
  96. *
  97. * @var string
  98. */
  99. public $name = null;
  100. /**
  101. * An array containing the names of helpers this controller uses. The array elements should
  102. * not contain the "Helper" part of the class name.
  103. *
  104. * Example:
  105. * ```
  106. * public $helpers = ['Form', 'Html', 'Time'];
  107. * ```
  108. *
  109. * @var mixed
  110. * @link http://book.cakephp.org/3.0/en/controllers.html#configuring-helpers-to-load
  111. */
  112. public $helpers = [];
  113. /**
  114. * An instance of a Cake\Network\Request object that contains information about the current request.
  115. * This object contains all the information about a request and several methods for reading
  116. * additional information about the request.
  117. *
  118. * @var \Cake\Network\Request
  119. * @link http://book.cakephp.org/3.0/en/controllers/request-response.html#request
  120. */
  121. public $request;
  122. /**
  123. * An instance of a Response object that contains information about the impending response
  124. *
  125. * @var \Cake\Network\Response
  126. * @link http://book.cakephp.org/3.0/en/controllers/request-response.html#response
  127. */
  128. public $response;
  129. /**
  130. * The class name to use for creating the response object.
  131. *
  132. * @var string
  133. */
  134. protected $_responseClass = 'Cake\Network\Response';
  135. /**
  136. * Settings for pagination.
  137. *
  138. * Used to pre-configure pagination preferences for the various
  139. * tables your controller will be paginating.
  140. *
  141. * @var array
  142. * @see \Cake\Controller\Component\PaginatorComponent
  143. */
  144. public $paginate = [];
  145. /**
  146. * Set to true to automatically render the view
  147. * after action logic.
  148. *
  149. * @var bool
  150. */
  151. public $autoRender = true;
  152. /**
  153. * Instance of ComponentRegistry used to create Components
  154. *
  155. * @var \Cake\Controller\ComponentRegistry
  156. */
  157. protected $_components = null;
  158. /**
  159. * Array containing the names of components this controller uses. Component names
  160. * should not contain the "Component" portion of the class name.
  161. *
  162. * Example:
  163. * ```
  164. * public $components = ['RequestHandler', 'Acl'];
  165. * ```
  166. *
  167. * @var array
  168. * @link http://book.cakephp.org/3.0/en/controllers/components.html
  169. */
  170. public $components = [];
  171. /**
  172. * Instance of the View created during rendering. Won't be set until after
  173. * Controller::render() is called.
  174. *
  175. * @var \Cake\View\View
  176. * @deprecated 3.1.0 Use getView() instead.
  177. */
  178. public $View;
  179. /**
  180. * These Controller properties will be passed from the Controller to the View as options.
  181. *
  182. * @var array
  183. * @see \Cake\View\View
  184. */
  185. protected $_validViewOptions = [
  186. 'viewVars', 'helpers', 'name', 'plugin', 'passedArgs'
  187. ];
  188. /**
  189. * Automatically set to the name of a plugin.
  190. *
  191. * @var string
  192. */
  193. public $plugin = null;
  194. /**
  195. * Holds all passed params.
  196. *
  197. * @var mixed
  198. */
  199. public $passedArgs = [];
  200. /**
  201. * Constructor.
  202. *
  203. * Sets a number of properties based on conventions if they are empty. To override the
  204. * conventions CakePHP uses you can define properties in your class declaration.
  205. *
  206. * @param \Cake\Network\Request|null $request Request object for this controller. Can be null for testing,
  207. * but expect that features that use the request parameters will not work.
  208. * @param \Cake\Network\Response|null $response Response object for this controller.
  209. * @param string|null $name Override the name useful in testing when using mocks.
  210. * @param \Cake\Event\EventManager|null $eventManager The event manager. Defaults to a new instance.
  211. */
  212. public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null)
  213. {
  214. if ($name !== null) {
  215. $this->name = $name;
  216. }
  217. if ($this->name === null && isset($request->params['controller'])) {
  218. $this->name = $request->params['controller'];
  219. }
  220. if ($this->name === null) {
  221. list(, $name) = namespaceSplit(get_class($this));
  222. $this->name = substr($name, 0, -10);
  223. }
  224. $this->setRequest($request !== null ? $request : new Request);
  225. $this->response = $response !== null ? $response : new Response;
  226. if ($eventManager !== null) {
  227. $this->eventManager($eventManager);
  228. }
  229. $this->modelFactory('Table', [$this->tableLocator(), 'get']);
  230. $modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
  231. $this->_setModelClass($modelClass);
  232. $this->initialize();
  233. $this->_mergeControllerVars();
  234. $this->_loadComponents();
  235. $this->eventManager()->on($this);
  236. }
  237. /**
  238. * Initialization hook method.
  239. *
  240. * Implement this method to avoid having to overwrite
  241. * the constructor and call parent.
  242. *
  243. * @return void
  244. */
  245. public function initialize()
  246. {
  247. }
  248. /**
  249. * Get the component registry for this controller.
  250. *
  251. * @return \Cake\Controller\ComponentRegistry
  252. */
  253. public function components()
  254. {
  255. if ($this->_components === null) {
  256. $this->_components = new ComponentRegistry($this);
  257. }
  258. return $this->_components;
  259. }
  260. /**
  261. * Add a component to the controller's registry.
  262. *
  263. * This method will also set the component to a property.
  264. * For example:
  265. *
  266. * ```
  267. * $this->loadComponent('Acl.Acl');
  268. * ```
  269. *
  270. * Will result in a `Toolbar` property being set.
  271. *
  272. * @param string $name The name of the component to load.
  273. * @param array $config The config for the component.
  274. * @return \Cake\Controller\Component
  275. */
  276. public function loadComponent($name, array $config = [])
  277. {
  278. list(, $prop) = pluginSplit($name);
  279. $this->{$prop} = $this->components()->load($name, $config);
  280. return $this->{$prop};
  281. }
  282. /**
  283. * Magic accessor for model autoloading.
  284. *
  285. * @param string $name Property name
  286. * @return bool|object The model instance or false
  287. */
  288. public function __get($name)
  289. {
  290. if (in_array($name, ['layout', 'view', 'theme', 'autoLayout', 'viewPath', 'layoutPath'], true)) {
  291. trigger_error(
  292. sprintf('Controller::$%s is deprecated. Use $this->getView()->%s() instead.', $name, $name),
  293. E_USER_DEPRECATED
  294. );
  295. return $this->getView()->{$name}();
  296. }
  297. list($plugin, $class) = pluginSplit($this->modelClass, true);
  298. if ($class !== $name) {
  299. return false;
  300. }
  301. return $this->loadModel($plugin . $class);
  302. }
  303. /**
  304. * Magic setter for removed properties.
  305. *
  306. * @param string $name Property name.
  307. * @param mixed $value Value to set.
  308. * @return void
  309. */
  310. public function __set($name, $value)
  311. {
  312. if (in_array($name, ['layout', 'view', 'theme', 'autoLayout', 'viewPath', 'layoutPath'], true)) {
  313. trigger_error(
  314. sprintf('Controller::$%s is deprecated. Use $this->getView()->%s() instead.', $name, $name),
  315. E_USER_DEPRECATED
  316. );
  317. $this->getView()->{$name}($value);
  318. return;
  319. }
  320. $this->{$name} = $value;
  321. }
  322. /**
  323. * Sets the request objects and configures a number of controller properties
  324. * based on the contents of the request. Controller acts as a proxy for certain View variables
  325. * which must also be updated here. The properties that get set are:
  326. *
  327. * - $this->request - To the $request parameter
  328. * - $this->plugin - To the $request->params['plugin']
  329. * - $this->passedArgs - Same as $request->params['pass]
  330. * - View::$plugin - $this->plugin
  331. *
  332. * @param \Cake\Network\Request $request Request instance.
  333. * @return void
  334. */
  335. public function setRequest(Request $request)
  336. {
  337. $this->request = $request;
  338. $this->plugin = isset($request->params['plugin']) ? $request->params['plugin'] : null;
  339. if (isset($request->params['pass'])) {
  340. $this->passedArgs = $request->params['pass'];
  341. }
  342. }
  343. /**
  344. * Dispatches the controller action. Checks that the action
  345. * exists and isn't private.
  346. *
  347. * @return mixed The resulting response.
  348. * @throws \LogicException When request is not set.
  349. * @throws \Cake\Controller\Exception\MissingActionException When actions are not defined or inaccessible.
  350. */
  351. public function invokeAction()
  352. {
  353. $request = $this->request;
  354. if (!isset($request)) {
  355. throw new LogicException('No Request object configured. Cannot invoke action');
  356. }
  357. if (!$this->isAction($request->params['action'])) {
  358. throw new MissingActionException([
  359. 'controller' => $this->name . "Controller",
  360. 'action' => $request->params['action'],
  361. 'prefix' => isset($request->params['prefix']) ? $request->params['prefix'] : '',
  362. 'plugin' => $request->params['plugin'],
  363. ]);
  364. }
  365. $callable = [$this, $request->params['action']];
  366. return call_user_func_array($callable, $request->params['pass']);
  367. }
  368. /**
  369. * Merge components, helpers vars from
  370. * parent classes.
  371. *
  372. * @return void
  373. */
  374. protected function _mergeControllerVars()
  375. {
  376. $this->_mergeVars(
  377. ['components', 'helpers'],
  378. ['associative' => ['components', 'helpers']]
  379. );
  380. }
  381. /**
  382. * Returns a list of all events that will fire in the controller during its lifecycle.
  383. * You can override this function to add you own listener callbacks
  384. *
  385. * @return array
  386. */
  387. public function implementedEvents()
  388. {
  389. return [
  390. 'Controller.initialize' => 'beforeFilter',
  391. 'Controller.beforeRender' => 'beforeRender',
  392. 'Controller.beforeRedirect' => 'beforeRedirect',
  393. 'Controller.shutdown' => 'afterFilter',
  394. ];
  395. }
  396. /**
  397. * Loads the defined components using the Component factory.
  398. *
  399. * @return void
  400. */
  401. protected function _loadComponents()
  402. {
  403. if (empty($this->components)) {
  404. return;
  405. }
  406. $registry = $this->components();
  407. $components = $registry->normalizeArray($this->components);
  408. foreach ($components as $properties) {
  409. $this->loadComponent($properties['class'], $properties['config']);
  410. }
  411. }
  412. /**
  413. * Perform the startup process for this controller.
  414. * Fire the Components and Controller callbacks in the correct order.
  415. *
  416. * - Initializes components, which fires their `initialize` callback
  417. * - Calls the controller `beforeFilter`.
  418. * - triggers Component `startup` methods.
  419. *
  420. * @return void|\Cake\Network\Response
  421. */
  422. public function startupProcess()
  423. {
  424. $event = $this->dispatchEvent('Controller.initialize');
  425. if ($event->result instanceof Response) {
  426. return $event->result;
  427. }
  428. $event = $this->dispatchEvent('Controller.startup');
  429. if ($event->result instanceof Response) {
  430. return $event->result;
  431. }
  432. }
  433. /**
  434. * Perform the various shutdown processes for this controller.
  435. * Fire the Components and Controller callbacks in the correct order.
  436. *
  437. * - triggers the component `shutdown` callback.
  438. * - calls the Controller's `afterFilter` method.
  439. *
  440. * @return void|\Cake\Network\Response
  441. */
  442. public function shutdownProcess()
  443. {
  444. $event = $this->dispatchEvent('Controller.shutdown');
  445. if ($event->result instanceof Response) {
  446. return $event->result;
  447. }
  448. }
  449. /**
  450. * Redirects to given $url, after turning off $this->autoRender.
  451. * Script execution is halted after the redirect.
  452. *
  453. * @param string|array $url A string or array-based URL pointing to another location within the app,
  454. * or an absolute URL
  455. * @param int $status HTTP status code (eg: 301)
  456. * @return void|\Cake\Network\Response
  457. * @link http://book.cakephp.org/3.0/en/controllers.html#Controller::redirect
  458. */
  459. public function redirect($url, $status = 302)
  460. {
  461. $this->autoRender = false;
  462. $response = $this->response;
  463. if ($status) {
  464. $response->statusCode($status);
  465. }
  466. $event = $this->dispatchEvent('Controller.beforeRedirect', [$url, $response]);
  467. if ($event->result instanceof Response) {
  468. return $event->result;
  469. }
  470. if ($event->isStopped()) {
  471. return;
  472. }
  473. if (!$response->location()) {
  474. $response->location(Router::url($url, true));
  475. }
  476. return $response;
  477. }
  478. /**
  479. * Internally redirects one action to another. Does not perform another HTTP request unlike Controller::redirect()
  480. *
  481. * Examples:
  482. *
  483. * ```
  484. * setAction('another_action');
  485. * setAction('action_with_parameters', $parameter1);
  486. * ```
  487. *
  488. * @param string $action The new action to be 'redirected' to.
  489. * Any other parameters passed to this method will be passed as parameters to the new action.
  490. * @return mixed Returns the return value of the called action
  491. */
  492. public function setAction($action)
  493. {
  494. $this->request->params['action'] = $action;
  495. $args = func_get_args();
  496. unset($args[0]);
  497. return call_user_func_array([&$this, $action], $args);
  498. }
  499. /**
  500. * Instantiates the correct view class, hands it its data, and uses it to render the view output.
  501. *
  502. * @param string $view View to use for rendering
  503. * @param string $layout Layout to use
  504. * @return \Cake\Network\Response A response object containing the rendered view.
  505. * @link http://book.cakephp.org/3.0/en/controllers.html#rendering-a-view
  506. */
  507. public function render($view = null, $layout = null)
  508. {
  509. $this->View = $this->getView();
  510. if (!$this->_view->viewPath()) {
  511. $this->_viewPath();
  512. }
  513. if (!empty($this->request->params['bare'])) {
  514. $this->_view->autoLayout(false);
  515. }
  516. $viewClass = $this->viewClass;
  517. $event = $this->dispatchEvent('Controller.beforeRender');
  518. if ($event->result instanceof Response) {
  519. $this->autoRender = false;
  520. return $event->result;
  521. }
  522. if ($event->isStopped()) {
  523. $this->autoRender = false;
  524. return $this->response;
  525. }
  526. // Re-fetch View class to pass view variables set in beforeRender callbacks
  527. $this->View = $this->getView();
  528. if ($viewClass !== $this->viewClass) {
  529. $this->View = $this->getView($this->viewClass);
  530. if (!$this->_view->viewPath()) {
  531. $this->_viewPath();
  532. }
  533. }
  534. $this->autoRender = false;
  535. if ($this->_view->view() === null &&
  536. isset($this->request->params['action'])
  537. ) {
  538. $this->_view->view($this->request->params['action']);
  539. }
  540. $this->response->body($this->_view->render($view, $layout));
  541. return $this->response;
  542. }
  543. /**
  544. * Set View::$viewPath property based on controller name and request prefix.
  545. *
  546. * @return void
  547. */
  548. protected function _viewPath()
  549. {
  550. $viewPath = $this->name;
  551. if (isset($this->request->params['prefix'])) {
  552. $prefixes = array_map(
  553. 'Cake\Utility\Inflector::camelize',
  554. explode('/', $this->request->params['prefix'])
  555. );
  556. $viewPath = implode(DS, $prefixes) . DS . $viewPath;
  557. }
  558. $this->_view->viewPath($viewPath);
  559. }
  560. /**
  561. * Returns the referring URL for this request.
  562. *
  563. * @param string|null $default Default URL to use if HTTP_REFERER cannot be read from headers
  564. * @param bool $local If true, restrict referring URLs to local server
  565. * @return string Referring URL
  566. */
  567. public function referer($default = null, $local = false)
  568. {
  569. if (!$this->request) {
  570. return Router::url($default, !$local);
  571. }
  572. $referer = $this->request->referer($local);
  573. if ($referer === '/' && $default && $default !== $referer) {
  574. return Router::url($default, !$local);
  575. }
  576. return $referer;
  577. }
  578. /**
  579. * Handles pagination of records in Table objects.
  580. *
  581. * Will load the referenced Table object, and have the PaginatorComponent
  582. * paginate the query using the request date and settings defined in `$this->paginate`.
  583. *
  584. * This method will also make the PaginatorHelper available in the view.
  585. *
  586. * @param \Cake\ORM\Table|string|\Cake\ORM\Query|null $object Table to paginate
  587. * (e.g: Table instance, 'TableName' or a Query object)
  588. * @return \Cake\ORM\ResultSet Query results
  589. * @link http://book.cakephp.org/3.0/en/controllers.html#Controller::paginate
  590. * @throws \RuntimeException When no compatible table object can be found.
  591. */
  592. public function paginate($object = null)
  593. {
  594. if (is_object($object)) {
  595. $table = $object;
  596. }
  597. if (is_string($object) || $object === null) {
  598. $try = [$object, $this->modelClass];
  599. foreach ($try as $tableName) {
  600. if (empty($tableName)) {
  601. continue;
  602. }
  603. $table = $this->loadModel($tableName);
  604. break;
  605. }
  606. }
  607. $this->loadComponent('Paginator');
  608. if (empty($table)) {
  609. throw new RuntimeException('Unable to locate an object compatible with paginate.');
  610. }
  611. return $this->Paginator->paginate($table, $this->paginate);
  612. }
  613. /**
  614. * Method to check that an action is accessible from a URL.
  615. *
  616. * Override this method to change which controller methods can be reached.
  617. * The default implementation disallows access to all methods defined on Cake\Controller\Controller,
  618. * and allows all public methods on all subclasses of this class.
  619. *
  620. * @param string $action The action to check.
  621. * @return bool Whether or not the method is accessible from a URL.
  622. */
  623. public function isAction($action)
  624. {
  625. try {
  626. $method = new ReflectionMethod($this, $action);
  627. } catch (ReflectionException $e) {
  628. return false;
  629. }
  630. if (!$method->isPublic()) {
  631. return false;
  632. }
  633. if ($method->getDeclaringClass()->name === 'Cake\Controller\Controller') {
  634. return false;
  635. }
  636. return true;
  637. }
  638. /**
  639. * Called before the controller action. You can use this method to configure and customize components
  640. * or perform logic that needs to happen before each controller action.
  641. *
  642. * @param Event $event An Event instance
  643. * @return void
  644. * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks
  645. */
  646. public function beforeFilter(Event $event)
  647. {
  648. }
  649. /**
  650. * Called after the controller action is run, but before the view is rendered. You can use this method
  651. * to perform logic or set view variables that are required on every request.
  652. *
  653. * @param Event $event An Event instance
  654. * @return void
  655. * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks
  656. */
  657. public function beforeRender(Event $event)
  658. {
  659. }
  660. /**
  661. * The beforeRedirect method is invoked when the controller's redirect method is called but before any
  662. * further action.
  663. *
  664. * If the event is stopped the controller will not continue on to redirect the request.
  665. * The $url and $status variables have same meaning as for the controller's method.
  666. * You can set the event result to response instance or modify the redirect location
  667. * using controller's response instance.
  668. *
  669. * @param Event $event An Event instance
  670. * @param string|array $url A string or array-based URL pointing to another location within the app,
  671. * or an absolute URL
  672. * @param \Cake\Network\Response $response The response object.
  673. * @return void
  674. * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks
  675. */
  676. public function beforeRedirect(Event $event, $url, Response $response)
  677. {
  678. }
  679. /**
  680. * Called after the controller action is run and rendered.
  681. *
  682. * @param Event $event An Event instance
  683. * @return void
  684. * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks
  685. */
  686. public function afterFilter(Event $event)
  687. {
  688. }
  689. }