1

我正在尝试在 ZF 中创建一个 dijit 按钮。我尝试过使用普通的 dojo 并且它可以工作,但是当使用 Zend_Dojo 时,它会创建一个简单的按钮,换句话说,Zend_Dojo_Form_Elements 充当 Zend_Form_Element。

没有 Zend_Dojo 的IndexController(这样按钮可以正确渲染):

$newEventButton = new Zend_Form_Element_Button('newEvent', array('dijitType'=>'dijit.form.Button');
$newEventButton->setLabel('New Event'); 
$this->view->newEventButton = $newEventButton;

带有 Zend_Dojo 的IndexController(这样它创建了一个简单的按钮,如下所示):

$newEventButton = new Zend_Dojo_Form_Element_Button('newEvent');
$newEventButton->setLabel('New Event'); 
$this->view->newEventButton = $newEventButton;

结果是:

enter code here
<button type="button" id="newEvent" name="newEvent">New event</button>

我做错了什么,为什么 Zend_Dojo_Form_Element 充当 Zend_Form_Element?谢谢。

4

2 回答 2

1

加载dojo时是否设置了parseOnLoad配置变量?

<script> djConfig = {parseOnLoad: true}; </script>
<script src="path to dojo"></script>
于 2011-07-30T14:52:22.620 回答
1

如果你只想创建一个按钮,直接使用视图助手(Zend_Dojo_View_Helper_Button)而不是使用表单元素(Zend_Dojo_Form_Element_Button)。在执行此操作之前,请确保在引导程序中包含 dojo 视图助手:

$view->addHelperPath(
    'Zend/Dojo/View/Helper/',
    'Zend_Dojo_View_Helper'
);

并确保在视图或布局中启用 Dojo 视图助手:

$view->dojo()->enable();

现在,直接使用视图助手 (Zend_Dojo_View_Helper_Button) 来呈现您的按钮(绕过 Zend_Dojo_Form_Element_Button,您应该只在构建完整表单时使用它)。在您看来:

echo $this->button('newEvent', null, array('label' => 'New Event', 'onclick' => 'someAction()'));

或者,如果您想在控制器中定义按钮:

$this->view->newEventButton = $this->view->button('newEvent', null, array('label' => 'New Event', 'onclick' => 'someAction()'));

然后在视图中渲染它:

echo $this->newEventButton;

希望能帮助到你!

于 2011-08-03T14:23:31.123 回答