ViewScript 装饰器无法设置

发布于 2024-11-28 18:54:32 字数 883 浏览 2 评论 0原文

我正在关注此页面中有关“使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三生殊途 2024-12-05 18:54:32

我认为事情就这么简单。

由于一个简单的原因,ViewScript 不能在表单的 init() 方法中使用。如果你看一下这个例子(可能还有你的display.phtml),就会有像这样的echo语句$this->form->firstname;。此时 init() 中表单元素尚未加载!

因此,作者正确地显示了这段代码

$form->setDecorators(array(
    array('ViewScript', array('script' => 'demogForm.phtml'))
));

,请注意,他使用 $form 作为对象。在控制器或视图脚本中,您将表单作为对象加载,然后添加 ViewScript。所以在你的一个控制器中你会做这样的事情

$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
    array('ViewScript', array('script' => $scriptPath))
));

这应该可以解决问题。

更新查看您的 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

$form->setDecorators(array(
    array('ViewScript', array('script' => 'demogForm.phtml'))
));

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 this

$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
    array('ViewScript', array('script' => $scriptPath))
));

This 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!

迟到的我 2024-12-05 18:54:32

使用视图脚本时,我发现最好在视图级别进行任何此类更改。

忽略表单中的“ViewScript”装饰器详细信息并从视图中设置它们,例如

<?php echo $this->form->setDecorators(array(
    'PrepareElements',
    array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>

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

<?php echo $this->form->setDecorators(array(
    'PrepareElements',
    array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>

The location of the display.phtml file is relative to the module's view scripts folder. If this is just the default module (under the application folder), the script in my example will be located at application/views/scripts/_forms/display.phtml

梦幻的心爱 2024-12-05 18:54:32

如果您想删除

(标签和视图脚本)等 HTML 标签,您可以使用方法 removeDecorator('HtmlTag')< /code> 或 removeDecorator('Label')

If you want to remove HTML tags like <dt> or <dd> (labels and viewscript) you can use methods removeDecorator('HtmlTag') or removeDecorator('Label')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文