ArticlesCell.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license http://www.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. * @return void
  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->template = 'derp';
  73. $this->counter++;
  74. $this->viewBuilder()->template('alternate_teaser_list');
  75. }
  76. /**
  77. * Renders a template in a custom templatePath
  78. * The template is set using the ViewBuilder bound to the Cell
  79. *
  80. * @return void
  81. */
  82. public function customTemplatePath()
  83. {
  84. $this->viewBuilder()->templatePath('Cell/Articles/Subdir');
  85. }
  86. /**
  87. * Simple echo.
  88. *
  89. * @param string $msg1
  90. * @param string $msg2
  91. * @return void
  92. */
  93. public function doEcho($msg1, $msg2)
  94. {
  95. $this->set('msg', $msg1 . $msg2);
  96. }
  97. }