PagesController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Static content controller.
  4. *
  5. * This file will render views from views/pages/
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org CakePHP(tm) Project
  17. * @package Cake.Controller
  18. * @since CakePHP(tm) v 0.2.9
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('AppController', 'Controller');
  22. /**
  23. * Static content controller
  24. *
  25. * Override this controller by placing a copy in controllers directory of an application
  26. *
  27. * @package Cake.Controller
  28. * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
  29. */
  30. class PagesController extends AppController {
  31. /**
  32. * Default helper
  33. *
  34. * @var array
  35. */
  36. public $helpers = array('Html', 'Session');
  37. /**
  38. * This controller does not use a model
  39. *
  40. * @var array
  41. */
  42. public $uses = array();
  43. /**
  44. * Displays a view
  45. *
  46. * @param mixed What page to display
  47. * @return void
  48. */
  49. public function display() {
  50. $path = func_get_args();
  51. $count = count($path);
  52. if (!$count) {
  53. $this->redirect('/');
  54. }
  55. $page = $subpage = $titleForLayout = null;
  56. if (!empty($path[0])) {
  57. $page = $path[0];
  58. }
  59. if (!empty($path[1])) {
  60. $subpage = $path[1];
  61. }
  62. if (!empty($path[$count - 1])) {
  63. $titleForLayout = Inflector::humanize($path[$count - 1]);
  64. }
  65. $this->set(array(
  66. 'page' => $page,
  67. 'subpage' => $subpage,
  68. 'title_for_layout' => $titleForLayout
  69. ));
  70. $this->render(implode('/', $path));
  71. }
  72. }