- <?php
- namespace app\controllers;
- use \Exception;
- use \juvo\cms\Page;
- use \juvo\util\Inflector;
- use \juvo\core\Loader;
- use \Zend_Config_Xml;
- use \Zend_Navigation;
- class IndexController extends \kernel\controllers\ControllerAbstract
- {
- const CMS_FORM_TOKEN = '%%FORM%%';
- public function init()
- {
- parent::init();
- $homePage = Page::findOneByUri('home');
- $this->view->siteNav = new Zend_Navigation($homePage->getChildren()->getNavDetails(2));
- }
- public function indexAction()
- {
- $page = Page::findOneByUri(ltrim($this->_request->getRequestUri(), "/"));
- if (!$page) {
- throw new Exception('Page cannot be found', 404);
- }
- $this->view->assign(array(
- 'page' => $page,
- 'pageTitle' => $page->title,
- ));
- $this->view->layout()->setLayout($page->layout);
- $this->render('page');
- }
- public function pageAction()
- {
- if (!$this->_hasParam('id')) {
- throw new Exception('Page cannot be found', 404);
- }
- $page = Page::findOne(filter_var($this->_request->id, FILTER_SANITIZE_NUMBER_INT));
- if (!$page) {
- throw new Exception('Page cannot be found', 404);
- }
- if (false !== strpos($page->content, static::CMS_FORM_TOKEN)) {
- $parts = explode('/', $page->uri);
- foreach ($parts as &$part) {
- $part = Inflector::slug($part, '_');
- $part = Inflector::camelize($part);
- }
- $formName = implode('_', $parts);
- $formClass = '\\app\\forms\\user\\' . $formName;
- if (Loader::load($formClass, false)) {
- $form = new $formClass();
- $page->content = $form->run($page, $this->view, $this->_request);
- }
- }
- $this->view->assign(array(
- 'page' => $page,
- 'pageTitle' => $page->title,
- ));
- if ($page->layout) {
- $this->view->layout()->setLayout($page->layout);
- }
- }
- }