PagesController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * For full copyright and license information, please see the LICENSE.txt
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  17. * @link http://cakephp.org CakePHP(tm) Project
  18. * @package app.Controller
  19. * @since CakePHP(tm) v 0.2.9
  20. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  21. */
  22. App::uses('AppController', 'Controller');
  23. /**
  24. * Static content controller
  25. *
  26. * Override this controller by placing a copy in controllers directory of an application
  27. *
  28. * @package app.Controller
  29. * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
  30. */
  31. class PagesController extends AppController {
  32. /**
  33. * Controller name
  34. *
  35. * @var string
  36. */
  37. public $name = 'Pages';
  38. /**
  39. * This controller does not use a model
  40. *
  41. * @var array
  42. */
  43. public $uses = array();
  44. /**
  45. * Displays a view
  46. *
  47. * @param mixed What page to display
  48. * @return void
  49. * @throws NotFoundException When the view file could not be found
  50. * or MissingViewException in debug mode.
  51. */
  52. public function display() {
  53. $path = func_get_args();
  54. $count = count($path);
  55. if (!$count) {
  56. return $this->redirect('/');
  57. }
  58. $page = $subpage = $title_for_layout = null;
  59. if (!empty($path[0])) {
  60. $page = $path[0];
  61. }
  62. if (!empty($path[1])) {
  63. $subpage = $path[1];
  64. }
  65. if (!empty($path[$count - 1])) {
  66. $title_for_layout = Inflector::humanize($path[$count - 1]);
  67. }
  68. $this->set(compact('page', 'subpage', 'title_for_layout'));
  69. try {
  70. $this->render(implode('/', $path));
  71. } catch (MissingViewException $e) {
  72. if (Configure::read('debug')) {
  73. throw $e;
  74. }
  75. throw new NotFoundException();
  76. }
  77. }
  78. }