ViewScript 装饰器无法设置
我正在关注此页面中有关“使用 ViewScript 装饰器进行完全自定义”的部分 -> http://devzone.zend.com/article/3450
在我的表单类的 init 方法中我已经添加了这个
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
现在在我的表单出现的地方我有这个:
发生错误
应用程序错误
我在这里做错了什么?我确实需要自定义表单的外观,我只想更改表单而不是整个页面的外观。
我已经尝试过这个:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
它有效但会影响整个页面的显示(我正在使用 zend 布局)。我只需要将表单的渲染传递到 display.phtml 页面。
注意:有什么地方我必须放置display.phtml吗?我将其放在 view\scripts 文件夹中。
I am following the section about "Full Customization Using the ViewScript Decorator" from this page -> http://devzone.zend.com/article/3450
In the init method of my form class I have added this
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
Now in the place where my form appeared I have this:
An error occurred
Application error
What am I doing wrong here? I really need to customize the appearance of the form and I just want to change the form and not the appearance of the whole page.
I have tried this:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
Which works but affects the display of the whole page (I am using zend layout). I just need the render of the form to be passed to the display.phtml page.
Note: Is there any place in particular I have to place the display.phtml? I placed it in the view\scripts folder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为事情就这么简单。
由于一个简单的原因,ViewScript 不能在表单的 init() 方法中使用。如果你看一下这个例子(可能还有你的display.phtml),就会有像这样的echo语句
$this->form->firstname;
。此时 init() 中表单元素尚未加载!因此,作者正确地显示了这段代码
,请注意,他使用
$form
作为对象。在控制器或视图脚本中,您将表单作为对象加载,然后添加 ViewScript。所以在你的一个控制器中你会做这样的事情这应该可以解决问题。
更新查看您的 pthml 的命名,我假设(并希望)这是您表单的特殊模板,而不是您的整个布局文件。如果您使用整个布局文件,那么当然会渲染整个页面!
I think it is as simple as this.
The ViewScript cannot be used in the init() method for your form for one simple reason. If you look at the example (and probably your display.phtml) there are echo statements like this one
$this->form->firstname;
. At this point in init() the form elements are not loaded yet!The author therefore correctly shows this code
Note that he uses
$form
as the object. Either in controller or view script you load your form as an object and then add the ViewScript. So in one of your controllers you would do something like thisThis should do the trick.
Update Looking at the naming of your pthml I assume (and hope) this is a special template for your form and not your whole layout file. If you use your whole layout file then of course if will render the whole page!
使用视图脚本时,我发现最好在视图级别进行任何此类更改。
忽略表单中的“ViewScript”装饰器详细信息并从视图中设置它们,例如
display.phtml
文件的位置相对于模块的视图脚本文件夹。如果这只是默认模块(在application
文件夹下),则我示例中的脚本将位于application/views/scripts/_forms/display.phtml
When working with view scripts, I find it's best to make any such changes at the view level.
Ignore the "ViewScript" decorator details in your form and set them from the view, eg
The location of the
display.phtml
file is relative to the module's view scripts folder. If this is just the default module (under theapplication
folder), the script in my example will be located atapplication/views/scripts/_forms/display.phtml
如果您想删除
或
removeDecorator('HtmlTag')< /code> 或
removeDecorator('Label')
If you want to remove HTML tags like
<dt>
or<dd>
(labels and viewscript) you can use methodsremoveDecorator('HtmlTag')
orremoveDecorator('Label')