• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/View/Helper/Partial.php

00001 <?php
00024 require_once 'Zend/View/Helper/Abstract.php';
00025 
00034 class Zend_View_Helper_Partial extends Zend_View_Helper_Abstract
00035 {
00040     protected $_objectKey;
00041 
00064     public function partial($name = null, $module = null, $model = null)
00065     {
00066         if (0 == func_num_args()) {
00067             return $this;
00068         }
00069 
00070         $view = $this->cloneView();
00071         if (isset($this->partialCounter)) {
00072             $view->partialCounter = $this->partialCounter;
00073         }
00074         if ((null !== $module) && is_string($module)) {
00075             require_once 'Zend/Controller/Front.php';
00076             $moduleDir = Zend_Controller_Front::getInstance()->getControllerDirectory($module);
00077             if (null === $moduleDir) {
00078                 require_once 'Zend/View/Helper/Partial/Exception.php';
00079                 throw new Zend_View_Helper_Partial_Exception('Cannot render partial; module does not exist');
00080             }
00081             $viewsDir = dirname($moduleDir) . '/views';
00082             $view->addBasePath($viewsDir);
00083         } elseif ((null == $model) && (null !== $module)
00084             && (is_array($module) || is_object($module)))
00085         {
00086             $model = $module;
00087         }
00088 
00089         if (!empty($model)) {
00090             if (is_array($model)) {
00091                 $view->assign($model);
00092             } elseif (is_object($model)) {
00093                 if (null !== ($objectKey = $this->getObjectKey())) {
00094                     $view->assign($objectKey, $model);
00095                 } elseif (method_exists($model, 'toArray')) {
00096                     $view->assign($model->toArray());
00097                 } else {
00098                     $view->assign(get_object_vars($model));
00099                 }
00100             }
00101         }
00102 
00103         return $view->render($name);
00104     }
00105 
00111     public function cloneView()
00112     {
00113         $view = clone $this->view;
00114         $view->clearVars();
00115         return $view;
00116     }
00117 
00124     public function setObjectKey($key)
00125     {
00126         if (null === $key) {
00127             $this->_objectKey = null;
00128         } else {
00129             $this->_objectKey = (string) $key;
00130         }
00131 
00132         return $this;
00133     }
00134 
00143     public function getObjectKey()
00144     {
00145         return $this->_objectKey;
00146     }
00147 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2