Exemplo n.º 1
0
 /**
  * Setup the view
  *
  * @param Zend_View_Abstract $view
  * @param Zend_Config $config
  */
 protected function _setupView(Zend_View_Abstract $view, Zend_Config $viewConfig)
 {
     // Add base, filter, helper and script paths
     $keys = array('base', 'filter', 'helper', 'script');
     foreach ($keys as $key) {
         foreach ($viewConfig->get('path')->get($key) as $objKey => $obj) {
             // Handle script paths
             if ($key == 'script') {
                 $view->addScriptPath(trim($obj));
                 continue;
             }
             // Handle base, filter and helper paths
             if ($obj instanceof Zend_Config || is_array($obj)) {
                 $path = $obj->get('path');
                 $prefix = $obj->get('prefix');
             } else {
                 // Allow setting namespaces using keys
                 if (empty($obj)) {
                     $obj = $objKey;
                 }
                 $path = str_replace('_', '/', $obj);
                 $prefix = $obj;
             }
             $method = 'add' . ucfirst($key) . 'Path';
             call_user_func_array(array($view, $method), array(trim($path), $prefix));
         }
     }
     // Filters
     $filters = $viewConfig->get('filter') instanceof Zend_Config ? $viewConfig->get('filter')->toArray() : array($viewConfig->get('filter'));
     foreach ($filters as $filter) {
         $view->addFilter($filter);
     }
     // Helpers
     $helpers = $viewConfig->get('helper') instanceof Zend_Config ? $viewConfig->get('helper')->toArray() : array();
     foreach ($helpers as $helper => $args) {
         $helperName = $this->_underscoreToCamelCase($helper);
         call_user_func_array(array($view, $helperName), $args);
     }
     // Set encoding
     if ($encoding = $viewConfig->get('encoding')) {
         $view->setEncoding($encoding);
     }
     // Set escape
     if ($escape = $viewConfig->get('escape')) {
         $view->setEscape($escape);
     }
     // Streams
     if ($view instanceof Zym_View_Abstract) {
         $this->_setupViewStreams($view, $viewConfig->get('stream'));
     }
 }