PostsController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp\Controller;
  16. use Cake\Event\Event;
  17. use TestApp\Controller\AppController;
  18. /**
  19. * PostsController class
  20. */
  21. class PostsController extends AppController
  22. {
  23. /**
  24. * Components array
  25. *
  26. * @var array
  27. */
  28. public $components = [
  29. 'Flash',
  30. 'RequestHandler',
  31. 'Security',
  32. ];
  33. /**
  34. * beforeFilter
  35. *
  36. * @return void
  37. */
  38. public function beforeFilter(Event $event)
  39. {
  40. if ($this->request->param('action') !== 'securePost') {
  41. $this->eventManager()->off($this->Security);
  42. }
  43. }
  44. /**
  45. * Index method.
  46. *
  47. * @param string $layout
  48. * @return void
  49. */
  50. public function index($layout = 'default')
  51. {
  52. $this->Flash->error('An error message');
  53. $this->response->cookie([
  54. 'name' => 'remember_me',
  55. 'value' => 1
  56. ]);
  57. $this->set('test', 'value');
  58. $this->viewBuilder()->setLayout($layout);
  59. }
  60. /**
  61. * Sets a flash message and redirects (no rendering)
  62. *
  63. * @return \Cake\Network\Response
  64. */
  65. public function flashNoRender()
  66. {
  67. $this->Flash->error('An error message');
  68. return $this->redirect(['action' => 'index']);
  69. }
  70. /**
  71. * Stub get method
  72. *
  73. * @return void
  74. */
  75. public function get()
  76. {
  77. // Do nothing.
  78. }
  79. /**
  80. * Post endpoint for integration testing with security component.
  81. *
  82. * @return void
  83. */
  84. public function securePost()
  85. {
  86. $this->response->body('Request was accepted');
  87. return $this->response;
  88. }
  89. public function file()
  90. {
  91. $this->response->file(__FILE__);
  92. return $this->response;
  93. }
  94. }