Zend Framework 的视图助手中需要 dojo.require 吗?
我尝试过使用 Dojo 按钮视图助手,但 Zend 似乎不会自动生成 dojo.require('dijit.form.Button')
。这是正确的行为吗?
以下是我的布局脚本的摘录:
<head>
<?= $this->dojo()->setDjConfigOption('usePlainJson',true)->addStylesheetModule('dijit.themes.claro')->setLocalPath("/js/dojo/dojo.js"); ?>
</head>
...
<?= $this->button('test', 'test') ?>
这是在我的引导程序中:
public function _initDojo() {
$view = $this->getResource('view');
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
Zend_Dojo::enableView($view);
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
}
除 dojo.require
之外,所有其他特定于 Dojo 的代码均已正确呈现。
I've tried using a Dojo button view helper, but it appears that Zend will not automatically generate a dojo.require('dijit.form.Button')
. Is this correct behavior?
Here's excerpt from my layout script:
<head>
<?= $this->dojo()->setDjConfigOption('usePlainJson',true)->addStylesheetModule('dijit.themes.claro')->setLocalPath("/js/dojo/dojo.js"); ?>
</head>
...
<?= $this->button('test', 'test') ?>
And this is in my bootstrap:
public function _initDojo() {
$view = $this->getResource('view');
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
Zend_Dojo::enableView($view);
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
}
All other Dojo-specific code is rendered properly, except the dojo.require
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有单独使用 dijit 助手,所以我只能为您提供部分答案。
当您在 Zend_Dojo_Form 中使用 dijit 元素时,ZF 肯定会自动添加适当的需求。从帮助程序代码来看,当您单独使用它们时,似乎也会发生这种情况。
如果您真的像示例中那样在 layout 中调用
$this->button
,那么我猜它不起作用只是因为 dojo 助手已经运行了呼叫您的助手的时间。您可以尝试将相同的调用移至视图脚本,看看这是否可以解决问题(视图脚本在布局之前呈现)。I've not used the dijit helpers on their own so I only have a partial answer for you.
ZF definitely automatically adds the appropriate requires when you use dijit elements in Zend_Dojo_Form. From looking at the helper code it looks like this should happen when you use them on their own as well.
If you are really calling
$this->button
in your layout as in your example, then I would guess that it's not working simply because the dojo helper has already run by the time your helper is called. You could try moving the same call to a view script instead to see if this solves the problem (view scripts are rendered before layouts).