【问题标题】:Zend_Dojo_Form in a layout布局中的 Zend_Dojo_Form
【发布时间】:2011-04-19 06:43:34
【问题描述】:

我有一个 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);

但这并没有什么不同。

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

【问题讨论】:

    标签: zend-framework dojo zend-layout


    【解决方案1】:

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

      <?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 中注册。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多