Zend 框架 - 表单不渲染
我刚刚开始使用 Zend Framework,并遵循最新版本 (1.11.10) 的快速入门文档。一切都很顺利,但是当我放置表单代码并运行应用程序时,表单没有呈现。我的代码完全类似于 http://framework.zend.com/ Manual/en/learning.quickstart.create-form.html
在视图上,我可以使用 var_dump($this->form);
转储表单 我尝试过 echo $this->form()
, echo $this->form->render()
,但什么也没有出现...是吗?
I'm just starting to use Zend Framework and was following the quick start documentation for the latest version (1.11.10). Everything was going just fine, but when I placed the form code and ran the application, the form did not render. My code is exactly like http://framework.zend.com/manual/en/learning.quickstart.create-form.html
On the view, I can dump the form just fine with var_dump($this->form);
I've tried echo $this->form()
, echo $this->form->render()
, but nothing appeared... What could it be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当 Zend 找不到元素的模板文件时,可能会出现此问题。查看以下代码:
文件
_input.phtml
必须位于该控制器的正确文件夹中。否则 Zend 无法找到输入模板,无法成功呈现您的元素,也不会显示任何内容。This problem can occur when Zend can't find the template file for an element. Look at following code:
The file
_input.phtml
must be in the right folder for this Controller. Otherwise Zend can't find the template for input and can't successfully render your element and will not show anything.确保将表单从控制器传递到视图。
在你的操作处理程序中:
在你看来:
我怀疑这是导致你的问题的原因,因为如果你尝试回显一个不支持的参数,Zend Framework 不会抱怨。不存在。 (即
echo $this->some_fake_parameter
不会执行任何操作)Make sure you pass the form to the view from the controller.
In your action handler:
In your view:
I suspected that this was the cause of your problem because Zend Framework doesn't complain if you try to echo a parameter that doesn't exist. (i.e.
echo $this->some_fake_parameter
won't do anything)好的,我尝试了你的代码,它对我来说没有问题。
这就是一切:
控制器
表单
查看
可以在以下位置看到:http://yaconiello. com/index/my-test
如果这对您不起作用,您可能遇到配置错误。
Ok so i tried your code, and it worked for me no problem.
Here is everything:
Controller
Form
View
can be seen on: http://yaconiello.com/index/my-test
If this isnt working for you, you may be having a configuration error.
我遇到了这样的问题(完全相同的形式,因为它是 Eclipse 示例)
我的问题是由于误解造成的。因为我认为我必须直接访问视图脚本。我在浏览器中输入如下内容:hostname/application/view/script/something.php
但在 zend 中,所有访问都应该通过公用文件夹。您必须访问这样的视图:hostname/app_name/public/guestbook
希望对你有帮助
I had a problem like that (exact same form, since it is eclipse example)
My problem was due to misunderstanding. Since I thought that I have to directly access to the view script. I entered in the browser something like: hostname/application/view/script/something.php
But in zend all accesses should be through public folder. You have to access to the view like this: hostname/app_name/public/guestbook
hope that would help you