Zend_Dojo_Form在布局中 [英] Zend_Dojo_Form in a layout

查看:132
本文介绍了Zend_Dojo_Form在布局中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

//将视图分配给viewRenderer,所以它将被MVC动作使用
$ viewRenderer = Zend_Controller_Action_HelperBroker :: getStaticHelper('ViewRenderer');
$ viewRenderer-> setView($ view);

return $ view;
}

没有错误(JS或ZF),表单只是不作为它应该。



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

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

但没有任何区别。



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

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

 <?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() - >内容?>
<?php echo $ this-> inlineScript()?>
< / body>
< / html>

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


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.

解决方案

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.

这篇关于Zend_Dojo_Form在布局中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆