SproutCMS

This is the code documentation for the SproutCMS project

source of /modules/Demo/Controllers/DemoController.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace SproutModules\Karmabunny\Demo\Controllers;
  15.  
  16. use InvalidArgumentException;
  17.  
  18. use Sprout\Controllers\Controller;
  19. use Sprout\Helpers\FrontEndEntrance;
  20. use Sprout\Helpers\Navigation;
  21. use Sprout\Helpers\Page;
  22. use Sprout\Helpers\TreenodeRedirectMatcher;
  23. use Sprout\Helpers\View;
  24.  
  25.  
  26. /**
  27.  * A basic demonstration of a front-end controller
  28.  */
  29. class DemoController extends Controller implements FrontEndEntrance
  30. {
  31.  
  32. public function _getEntranceArguments()
  33. {
  34. return [
  35. 'aaa' => 'AAA',
  36. 'bbb' => 'BBB',
  37. ];
  38. }
  39.  
  40.  
  41. public function entrance($argument)
  42. {
  43. switch ($argument) {
  44. case 'aaa': $this->aaa(); break;
  45. case 'bbb': $this->bbb(); break;
  46. default:
  47. throw new InvalidArgumentException();
  48. }
  49. }
  50.  
  51.  
  52. public function aaa()
  53. {
  54. Navigation::setPageNodeMatcher(new TreenodeRedirectMatcher('aaa'));
  55.  
  56. $page = Page::setupToolPage();
  57.  
  58. $view = new View('modules/Demo/aaa');
  59.  
  60. $skin = new View('skin/inner');
  61. Page::injectPageSkin($skin, $page);
  62. $skin->main_content = $view->render();
  63. echo $skin->render();
  64. }
  65.  
  66.  
  67. public function bbb()
  68. {
  69. Navigation::setPageNodeMatcher(new TreenodeRedirectMatcher('bbb'));
  70.  
  71. $view = new View('modules/Demo/bbb');
  72.  
  73. $skin = new View('skin/wide');
  74. $skin->page_title = 'BBB';
  75. $skin->main_content = $view->render();
  76. echo $skin->render();
  77. }
  78.  
  79. }