布局中的 Zend_Dojo_Form

发布于 2024-09-25 16:39:21 字数 1440 浏览 9 评论 0原文

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

但这没有任何区别。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烙印 2024-10-02 16:39:21

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

  <?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()< /strong> 否则所需的模块将不会在 Zend_Dojo 中注册。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文