PagesController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * This controller does not use a model
  34. *
  35. * @var array
  36. */
  37. public $uses = array();
  38. /**
  39. * Displays a view
  40. *
  41. * @param mixed What page to display
  42. * @return void
  43. * @throws NotFoundException When the view file could not be found
  44. * or MissingViewException in debug mode.
  45. */
  46. public function display() {
  47. $path = func_get_args();
  48. $count = count($path);
  49. if (!$count) {
  50. return $this->redirect('/');
  51. }
  52. $page = $subpage = $title_for_layout = null;
  53. if (!empty($path[0])) {
  54. $page = $path[0];
  55. }
  56. if (!empty($path[1])) {
  57. $subpage = $path[1];
  58. }
  59. if (!empty($path[$count - 1])) {
  60. $title_for_layout = Inflector::humanize($path[$count - 1]);
  61. }
  62. $this->set(compact('page', 'subpage', 'title_for_layout'));
  63. try {
  64. $this->render(implode('/', $path));
  65. } catch (MissingViewException $e) {
  66. if (Configure::read('debug')) {
  67. throw $e;
  68. }
  69. throw new NotFoundException();
  70. }
  71. }
  72. }