Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 2.18 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. namespace app\controllers;
  4.  
  5. use \Exception;
  6. use \juvo\cms\Page;
  7. use \juvo\util\Inflector;
  8. use \juvo\core\Loader;
  9. use \Zend_Config_Xml;
  10. use \Zend_Navigation;
  11.  
  12. class IndexController extends \kernel\controllers\ControllerAbstract
  13. {
  14.     const CMS_FORM_TOKEN = '%%FORM%%';
  15.        
  16.     public function init()
  17.     {
  18.         parent::init();
  19.        
  20.         $homePage = Page::findOneByUri('home');
  21.         $this->view->siteNav = new Zend_Navigation($homePage->getChildren()->getNavDetails(2));
  22.     }
  23.    
  24.     public function indexAction()
  25.     {
  26.         $page = Page::findOneByUri(ltrim($this->_request->getRequestUri(), "/"));
  27.        
  28.         if (!$page) {
  29.             throw new Exception('Page cannot be found', 404);
  30.         }
  31.        
  32.         $this->view->assign(array(
  33.             'page'      => $page,
  34.             'pageTitle' => $page->title,
  35.         ));
  36.  
  37.         $this->view->layout()->setLayout($page->layout);
  38.         $this->render('page');
  39.     }
  40.    
  41.     public function pageAction()
  42.     {
  43.         if (!$this->_hasParam('id')) {
  44.             throw new Exception('Page cannot be found', 404);
  45.         }
  46.        
  47.         $page = Page::findOne(filter_var($this->_request->id, FILTER_SANITIZE_NUMBER_INT));
  48.  
  49.         if (!$page) {
  50.             throw new Exception('Page cannot be found', 404);
  51.         }
  52.  
  53.         if (false !== strpos($page->content, static::CMS_FORM_TOKEN)) {
  54.             $parts = explode('/', $page->uri);
  55.            
  56.             foreach ($parts as &$part) {
  57.                 $part = Inflector::slug($part, '_');
  58.                 $part = Inflector::camelize($part);
  59.             }
  60.            
  61.             $formName = implode('_', $parts);
  62.             $formClass = '\\app\\forms\\user\\' . $formName;
  63.            
  64.             if (Loader::load($formClass, false)) {
  65.                 $form = new $formClass();
  66.                 $page->content = $form->run($page, $this->view, $this->_request);
  67.             }
  68.         }
  69.  
  70.         $this->view->assign(array(
  71.             'page'      => $page,
  72.             'pageTitle' => $page->title,
  73.         ));
  74.  
  75.         if ($page->layout) {
  76.             $this->view->layout()->setLayout($page->layout);
  77.         }
  78.     }
  79. }