Zend_Dojo_Form_Element创建简单元素("acting"Zend_Form_Ele



我试图在ZF中创建一个dijit按钮。我试过使用纯dojo,它的工作原理,但当使用Zend_Dojo创建一个简单的按钮,换句话说,Zend_Dojo_Form_Elements作为Zend_Form_Element。

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

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

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

$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?谢谢。

如果你只是想创建一个按钮,直接使用视图帮助器(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;

希望有帮助!

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

<script> djConfig = {parseOnLoad: true}; </script>
<script src="path to dojo"></script>

相关内容

最新更新