开发者

Zend_Dojo_Form in a layout

开发者 https://www.devze.com 2023-01-18 17:34 出处:网络
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 p开发者_Python百科age. However in the layout the form no lon

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 p开发者_Python百科age. 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消