ArticlesCell.php 2.6 KB

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