Zend_Dojo_Form_Element 创建简单元素(“充当” Zend_Form_Element)

Posted

技术标签:

【中文标题】Zend_Dojo_Form_Element 创建简单元素(“充当” Zend_Form_Element)【英文标题】:Zend_Dojo_Form_Element creating simple elements ("acting" as Zend_Form_Element) 【发布时间】:2011-07-30 14:41:34 【问题描述】:

我正在尝试在 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 和 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?谢谢。

【问题讨论】:

【参考方案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;

希望对你有帮助!

【讨论】:

我的引导程序中包含了视图助手,并且我在布局中启用了 Dojo,这是使用我的问题中描述的第一种方法的方式,按钮呈现为 dijit 按钮。我也试过你的方法。还是没有结果。我真的需要让它工作,因为在某些时候我将使用 Zend_Dojo_Form 并且我需要将它创建为 dijit.form.Form 类型,而不是简单的表单。 没有错误,一切正常。现在我看到了您对 Zend_Dojo_View_Helper_Button 的编辑。我不知道。感谢您的提示! 是的,最初的帖子可能令人困惑,所以我明确区分了 View Helper 和 Form Element;后者使用前者使用装饰器渲染按钮(ViewHelper 装饰器用于普通表单元素,Dijit 装饰器用于 dojo 表单元素);但是,Form Element 类仅在完整表单的上下文中真正有用;如果你只想要一个按钮或一个移位的表单元素,直接使用视图助手会更容易。【参考方案2】:

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

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

【讨论】:

是的。反正我也用了你的方法,还是一无所获:( 好吧,您至少可以通过编程方式(在 javascript 中)创建小部件吗? 我可以试试,但这不是我想要的;我已经有大量的js了。 然后看看你是否可以通过手动调用 dojo.parser.parse( the_root_dom_node_to_convert ) -- dojo.require('dojo.parser') 来渲染你的小部件,ofc the_root_dom_node_to_convert = id 或对象。我想我不明白我必须做什么......

以上是关于Zend_Dojo_Form_Element 创建简单元素(“充当” Zend_Form_Element)的主要内容,如果未能解决你的问题,请参考以下文章

创建表的时候创建索引

Spark SQL怎么创建编程创建DataFrame

要用MFC创建一个窗口,如何创建?

oracle 安装完了,怎么创建用户和数据库???

oracle 安装完了,怎么创建用户和数据库???

mysql在创建表的时候可以创建字段那么创建新数据库的时候可以顺便创建表吗