Zend_Dojo_Form in a layout

早过忘川 提交于 2019-12-10 17:56:57

问题


I have a Zend_Dojo_Form which I have moved from my view (where it works fine) to my layout, as it's something that will be useful on every page. However in the layout the form no longer works - none of the dijit elements appear and it behaves just as a normal HTML form would.

Here's the relevant part of my bootstrap:

protected function _initView()
{
    Zend_Layout::startMvc(array(
        'layoutPath' => '../application/layouts',
        'layout' => 'default'
    ));

    $view = new Zend_View();
    $view->setEncoding('UTF-8')
         ->doctype('HTML5');

    // init Dojo
    Zend_Dojo::enableView($view);
    $view->dojo()->enable()
                 ->setCdnVersion('1.5')
                 ->requireModule('dojo.data.ItemFileWriteStore')
                 [...]
                 ->addStyleSheetModule('dijit.themes.tundra');

    // assign the view to the viewRenderer, so it will be used by the MVC actions
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
    $viewRenderer->setView($view);

    return $view;
}

there are no errors (JS or ZF), the form just doesn't work as it should.

I assume I need to Dojo enable the Layout view in some way. I tried changing the layout part of the bootstrap method above to this:

$layout = Zend_Layout::startMvc(array(
    'layoutPath' => '../application/layouts',
    'layout' => 'default'
));
$view = $layout->getView();
Zend_Dojo::enableView($view);
$layout->setView($view);

but that didn't make any difference.

I found this question which sounds very similar to my problem, but the accepted answer just shows including the dojo helper in the layout, which I am doing already.


回答1:


This is most probably due to that you have the layout as suggested in the docs:

  <?php echo $this->doctype() ?>
  <html>
  <head>
      <?php echo $this->headTitle() ?>
      <?php echo $this->headMeta() ?>
      <?php echo $this->headLink() ?>
      <?php echo $this->headStyle() ?>
  <?php if ($this->dojo()->isEnabled()){
      $this->dojo()->setLocalPath('/js/dojo/dojo.js')
                   ->addStyleSheetModule('dijit.themes.tundra');
      echo $this->dojo();
     }
  ?>
      <?php echo $this->headScript() ?>
  </head>
  <body class="tundra">
      <?php echo $this->layout()->content ?>
      <?php echo $this->inlineScript() ?>
  </body>
  </html>

The problem is the echo $this->dojo() must be after the $this->form->render() otherwise the required modules won't have been registered in Zend_Dojo.



来源:https://stackoverflow.com/questions/3829609/zend-dojo-form-in-a-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!