/** * Set initial settings and call init() * * @param array $settings */ function __construct($settings = array()) { $this->settings = $settings; $layout = Zend_Layout::getMvcInstance(); $this->view = $layout->getView(); // Add module paths to view scripts $this->view->addBasePath(ZfApplication::$_base_path . "/app/Flex/views", "Flex_View"); $this->view->addScriptPath($layout->getLayoutPath() . "default/templates/Flex/"); $this->view->addScriptPath($layout->getLayoutPath() . $layout->getLayout() . "/templates/Flex/"); $this->init(); }
/** * Render a hook's content * * @param string $name template to use * @param string $module module to fetch template from * @param string $controller controller to fetch template from, defaults to 'hooks' * * @return string Rendered content * */ public function render($name, $module, $controller = "hooks") { $layout = Zend_Layout::getMvcInstance(); // Reset view script paths $this->view->setScriptPath(null); // Build new ones for hooks $this->view->addBasePath(ZfApplication::$_base_path . "/app/{$module}/views", $module . "_View"); //$this->view->addScriptPath(ZfApplication::$_base_path."/app/$module/Views/"); $this->view->addScriptPath($layout->getLayoutPath() . "default/templates/{$module}"); $this->view->addScriptPath($layout->getLayoutPath() . $layout->getLayout() . "/templates/{$module}"); return $this->view->render($controller . "/" . $name); }
/** * 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')); } }
/** * Add a script path to the view. * * @internal Overrides Zend_View_Abstract to ensure that duplicate paths * are not added to the stack. Fixes a bug where include'ing the same * script twice causes fatal errors. * @param string $path Local filesystem path. */ public function addScriptPath($path) { // For some unknown reason, Zend_View adds a trailing slash to paths. // Need to add that for the purposes of comparison. $path = rtrim($path, '/') . '/'; if (!in_array($path, $this->getScriptPaths())) { return parent::addScriptPath($path); } }
public function addScriptPath($path) { $this->_pathSet = false; return parent::addScriptPath($path); }
/** * Reset the view's script paths and set new ones for use in the block * * @param Zend_View_Abstract $view */ private function resetViewScripts(Zend_View_Abstract $view) { $layout = Zend_Layout::getMvcInstance(); // Reset view script paths $view->setScriptPath(null); $module = ucfirst($this->module); // Build new ones for blocks $view->addBasePath(ZfApplication::$_base_path . "/app/{$module}/views", $module . "_View"); $view->addScriptPath(ZfApplication::$_base_path . "/app/{$module}/views/scripts/blocks"); $view->addScriptPath($layout->getLayoutPath() . "default/templates/blocks"); $view->addScriptPath($layout->getLayoutPath() . "default/templates/{$module}/blocks"); $view->addScriptPath($layout->getLayoutPath() . $layout->getLayout() . "/templates/blocks"); $view->addScriptPath($layout->getLayoutPath() . $layout->getLayout() . "/templates/{$module}/blocks"); }