从 Zend 中的视图助手加载 Zend_Form?
是否可以从视图助手加载 Zend_Form?我在登录操作方法中使用此表单。但我也希望此表单在每个页面的导航中都可见(因此尚未实际调用登录操作),表单的 post 方法将发送到登录操作方法。
我猜应该用视图助手来完成,但我不知道如何做。
有什么想法吗?
我尝试过这个: 我的视图助手:
class Zend_View_Helper_LoginForm
{
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
我从我的布局中调用它,如下所示: form(); ?>
但这不起作用。 (不过,我可以通过操作方法调用相同的表单!)
在这种情况下,它会给我这个错误(这没有意义,因为我的助手只有 9 行长):
警告:缺少参数 1对于 Zend_View_Helper_Form::form() 在 C:\xampplite\htdocs\zendpr\library\Zend\View\Helper\Form.php 第 44 行
Is it possible to load a Zend_Form from a view helper? I'm using thise form in a login action method. But I also want this form to be visible on the navigation on every page (so without the login action actually being called yet), the post method of the form will send to the login action method.
I'm guessing it should be done with a view helper but I don't see how.
Any ideas?
I tried with this:
my view helper:
class Zend_View_Helper_LoginForm
{
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
and I call it from my layout like this:<?php echo $this->form(); ?>
but this doesn't work. (I'm able to call the same form through an action method though!)
In this case it gives me this error (which doesn't make sense because my helper is only 9 lines long):
Warning: Missing argument 1 for Zend_View_Helper_Form::form() in C:\xampplite\htdocs\zendpr\library\Zend\View\Helper\Form.php on line 44
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的视图助手应该扩展 Zend_View_Helper_Abstract 类,并且视图助手的方法必须与该类具有相同的名称:
并且您在视图脚本中这样调用它:
如果您调用:
您正在使用视图助手 Zend_View_Helper_Form
Your view helper should extends the Zend_View_Helper_Abstract class and the method of the view helper must have the same name as the class :
and you call it like this in your view script :
If you call :
You are using the view helper Zend_View_Helper_Form
让您的 View_Helper 扩展 Zend_View_Helper_Abstract 并覆盖 setView()
在控制器操作中初始化表单并设置表单引用
然后在视图助手中您可以通过视图引用表单
Have your View_Helper extend Zend_View_Helper_Abstract and override the setView()
Initialise the form in your controller action and set the form reference
Then in the view helper you can reference the form via the view
或
$this->view->form=$form;
两者都会返回表单。视图形式对于视图来说更加具体。
将其添加到您的 phtml 视图文件中
echo $this->form();
要回答这个问题 - 删除括号
应该是
echo $this->form;
OR
$this->view->form=$form;
Both are going to return the form. The view form is more specific for view.
Add this into your phtml view file
echo $this->form();
To answer this question - Remove the Parenthetical
Should be
echo $this->form;