Beispiel #1
0
 /**
  * Set the view object
  *
  * Ensures that the view object has the dojo view helper path set.
  *
  * @param  \Zend\View\ViewEngine $view
  * @return \Zend\Dojo\Form\Element\Dijit
  */
 public function setView(View $view = null)
 {
     if (null !== $view) {
         if (false === $view->getPluginLoader('helper')->getPaths('Zend\\Dojo\\View\\Helper')) {
             $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend\\Dojo\\View\\Helper');
         }
     }
     return parent::setView($view);
 }
Beispiel #2
0
 /**
  * Retrieve view object
  *
  * @return \Zend\View\View
  */
 public function getView()
 {
     if (null === $this->_view) {
         $options = $this->getOptions();
         $this->_view = new \Zend\View\View($options);
         if (isset($options['doctype'])) {
             $this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
         }
     }
     return $this->_view;
 }
Beispiel #3
0
 /**
  * Render a view script (optionally to a named response segment)
  *
  * Sets the noRender flag to true when called.
  *
  * @param  string $script
  * @param  string $name
  * @return void
  */
 public function renderScript($script, $name = null)
 {
     if (null === $name) {
         $name = $this->getResponseSegment();
     }
     $this->getResponse()->appendBody($this->view->render($script), $name);
     $this->setNoRender();
 }
Beispiel #4
0
 /**
  * Render dojo module paths and requires
  *
  * @return string
  */
 protected function _renderExtras()
 {
     $js = array();
     $modulePaths = $this->getModulePaths();
     if (!empty($modulePaths)) {
         foreach ($modulePaths as $module => $path) {
             $js[] = 'dojo.registerModulePath("' . $this->view->vars()->escape($module) . '", "' . $this->view->vars()->escape($path) . '");';
         }
     }
     $modules = $this->getModules();
     if (!empty($modules)) {
         foreach ($modules as $module) {
             $js[] = 'dojo.require("' . $this->view->vars()->escape($module) . '");';
         }
     }
     $onLoadActions = array();
     // Get Zend specific onLoad actions; these will always be first to
     // ensure that dijits are created in the correct order
     foreach ($this->_getZendLoadActions() as $callback) {
         $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');';
     }
     // Get all other onLoad actions
     foreach ($this->getOnLoadActions() as $callback) {
         $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');';
     }
     $javascript = implode("\n    ", $this->getJavascript());
     $content = '';
     if (!empty($js)) {
         $content .= implode("\n    ", $js) . "\n";
     }
     if (!empty($onLoadActions)) {
         $content .= implode("\n    ", $onLoadActions) . "\n";
     }
     if (!empty($javascript)) {
         $content .= $javascript . "\n";
     }
     if (preg_match('/^\\s*$/s', $content)) {
         return '';
     }
     $html = '<script type="text/javascript">' . PHP_EOL . ($this->_isXhtml ? '//<![CDATA[' : '//<!--') . PHP_EOL . $content . ($this->_isXhtml ? '//]]>' : '//-->') . PHP_EOL . PHP_EOL . '</script>';
     return $html;
 }
Beispiel #5
0
 /**
  * Recurse through a form object, rendering errors
  *
  * @param  \Zend\Form\Form $form
  * @param  \Zend\View\ViewEngine $view
  * @return string
  */
 protected function _recurseForm(Form\Form $form, View $view)
 {
     $content = '';
     $custom = $form->getCustomMessages();
     if ($this->getShowCustomFormErrors() && count($custom)) {
         $content .= $this->getMarkupListItemStart() . $view->formErrors($custom, $this->getOptions()) . $this->getMarkupListItemEnd();
     }
     foreach ($form->getElementsAndSubFormsOrdered() as $subitem) {
         if ($subitem instanceof Form\Element && !$this->getOnlyCustomFormErrors()) {
             $messages = $subitem->getMessages();
             if (count($messages)) {
                 $subitem->setView($view);
                 $content .= $this->getMarkupListItemStart() . $this->renderLabel($subitem, $view) . $view->formErrors($messages, $this->getOptions()) . $this->getMarkupListItemEnd();
             }
         } elseif ($subitem instanceof Zend\Form && !$this->ignoreSubForms()) {
             $content .= $this->getMarkupListStart() . $this->_recurseForm($subitem, $view) . $this->getMarkupListEnd();
         }
     }
     return $content;
 }
Beispiel #6
0
 /**
  * Initialize View object
  *
  * Initializes {@link $view} if not otherwise a Zend_View_Interface.
  *
  * If {@link $view} is not otherwise set, instantiates a new Zend_View
  * object, using the 'views' subdirectory at the same level as the
  * controller directory for the current module as the base directory.
  * It uses this to set the following:
  * - script path = views/scripts/
  * - helper path = views/helpers/
  * - filter path = views/filters/
  *
  * @return \Zend\View\ViewEngine
  * @throws \Zend\Controller\Exception if base view directory does not exist
  */
 public function initView()
 {
     $broker = $this->broker();
     if (!$this->getInvokeArg('noViewRenderer') && $broker && $broker->hasPlugin('viewRenderer')) {
         return $this->view;
     }
     if (isset($this->view) && $this->view instanceof View\Renderer) {
         return $this->view;
     }
     $request = $this->getRequest();
     $module = $request->getModuleName();
     $dirs = $this->getFrontController()->getControllerDirectory();
     if (empty($module) || !isset($dirs[$module])) {
         $module = $this->getFrontController()->getDispatcher()->getDefaultModule();
     }
     $baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views';
     if (!file_exists($baseDir) || !is_dir($baseDir)) {
         throw new Exception('Missing base view directory ("' . $baseDir . '")');
     }
     $this->view = new View\PhpRenderer();
     $this->view->resolver()->addPath($baseDir . '/scripts');
     return $this->view;
 }
Beispiel #7
0
 /**
  * Dojo-enable a view instance
  *
  * @param  \Zend\View\ViewEngine $view
  * @return void
  */
 public static function enableView(View $view)
 {
     if (false === $view->getPluginLoader('helper')->getPaths('Zend\\Dojo\\View\\Helper')) {
         $view->addHelperPath('Zend/Dojo/View/Helper', 'Zend\\Dojo\\View\\Helper');
     }
 }