ArticlesCell.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace TestApp\View\Cell;
  16. use Cake\View\Cell;
  17. /**
  18. * TagCloudCell class
  19. */
  20. class ArticlesCell extends Cell
  21. {
  22. /**
  23. * valid cell options.
  24. *
  25. * @var array<string>
  26. */
  27. protected $_validCellOptions = ['limit', 'page'];
  28. /**
  29. * Counter used to test the cache cell feature
  30. *
  31. * @var int
  32. */
  33. public $counter = 0;
  34. /**
  35. * Default cell action.
  36. */
  37. public function display(): void
  38. {
  39. }
  40. /**
  41. * Renders articles in teaser view mode.
  42. */
  43. public function teaserList(): void
  44. {
  45. $this->set('articles', [
  46. ['title' => 'Lorem ipsum', 'body' => 'dolorem sit amet'],
  47. ['title' => 'Usectetur adipiscing eli', 'body' => 'tortor, in tincidunt sem dictum vel'],
  48. ['title' => 'Topis semper blandit eu non', 'body' => 'alvinar diam convallis non. Nullam pu'],
  49. ['title' => 'Suspendisse gravida neque', 'body' => 'pellentesque sed scelerisque libero'],
  50. ]);
  51. }
  52. /**
  53. * Renders a view using a different template than the action name
  54. * The template is set using the ViewBuilder bound to the Cell
  55. */
  56. public function customTemplateViewBuilder(): void
  57. {
  58. $this->counter++;
  59. $this->viewBuilder()->setTemplate('alternate_teaser_list');
  60. }
  61. /**
  62. * Renders a template in a custom templatePath
  63. * The template is set using the ViewBuilder bound to the Cell
  64. */
  65. public function customTemplatePath(): void
  66. {
  67. $this->viewBuilder()->setTemplatePath(static::TEMPLATE_FOLDER . '/Articles/Subdir');
  68. }
  69. /**
  70. * Simple echo.
  71. */
  72. public function doEcho(string $msg1, string $msg2): void
  73. {
  74. $this->set('msg', $msg1 . $msg2);
  75. }
  76. }