3

我有一个 Zend_Dojo_Form,我已经从我的视图(它工作正常的地方)移动到我的布局,因为它在每个页面上都会有用。然而,在布局中,表单不再起作用 - 没有任何 dijit 元素出现,它的行为与普通 HTML 表单一样。

这是我的引导程序的相关部分:

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;
}

没有错误(JS 或 ZF),表单无法正常工作。

我假设我需要 Dojo 以某种方式启用布局视图。我尝试将上面的引导方法的布局部分更改为:

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

但这没有任何区别。

我发现这个问题听起来与我的问题非常相似,但接受的答案只显示在布局中包括 dojo 助手,我已经在这样做了。

4

1 回答 1

4

这很可能是因为您具有文档中建议的布局:

  <?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>

问题是echo $this->dojo() 必须在 $this->form->render() 之后,否则所需的模块将不会在 Zend_Dojo 中注册。

于 2011-01-05T13:24:50.280 回答