如何解决通知:未定义的变量:表单...?
当我创建页面indexSuccess.php时,我使用了如下指令:
<?php echo $form['titre']->render();?>
执行时它给了我一个错误:
Notice: Undefined variable: form in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84
Fatal error: Call to a member function render() on a non-object in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84
我可以做什么来解决该问题?
when I have created my page indexSuccess.php, i used an instruction like :
<?php echo $form['titre']->render();?>
it gives me an error when executing like :
Notice: Undefined variable: form in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84
Fatal error: Call to a member function render() on a non-object in C:\wamp\www\MyProject\apps\frontend\modules\addAnnonce\templates\indexSuccess.php on line 84
what can I doas solution for that problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您自动生成学说模型时,该表单将作为部分创建并嵌入到新的 & 模型中。编辑模板。如果您检查 newSuccess、createSuccess、editSuccess、updateSuccess 操作,您会发现 prodigitalson 提到的表单变量的赋值,因此不会出现此错误。
但是,该表单不会自动在indexSuccess 上可用,因为按照命名约定,该页面应该用于列出对象。打破约定可能会导致以后出现一些混乱。
还有一点提示:如果您想创建一个类似于 symfony 管理后端的屏幕,在其中列出所有对象以及用于添加/编辑对象的表单,您可以使用生成器.yml 自动生成视图。确保包含 symfony 目录中 web/sf 文件夹中的 css、js 和图像
When you auto-generate a doctrine model, the form is created as a partial and embedded in the new & edit templates. If you check your newSuccess, createSuccess, editSuccess, updateSuccess actions, you will find the assignment of the form variable as mentioned by prodigitalson, so this error wont appear there.
However, the form is not automatically made available on indexSuccess, as that page by naming convention is supposed to be used for listing out the objects. Breaking the convention might lead to some confusion later.
One more tip: if you want to create a screen similar to the symfony admin backend, where you list all objects along with a form to add/edit objects, you can use generator.yml to automatically generate your views. Be sure to include css,js&images from web/sf folder in the symfony directory
所以,我找到了我正在寻找的东西。我忘记添加
我的executeIndex(action)
thx:)
So, I found what I'm searching for. I forgot to add
in my executeIndex(action)
thx :)