[英]Create unique form fields based on database query in Symfony 1.4/Doctrine 1.2
I have this wild project happening at work, and we happen to use Symfony 1.4 so I was hoping, ideally, to keep this project within the framework's capabilities as much as possible. 我正在执行一个疯狂的项目,我们碰巧使用了Symfony 1.4,因此,我希望在理想情况下,尽可能将这个项目保持在框架的功能范围内。 Unfortunately, despite quite a bit of research and searching, I haven't yet found a way to generate sfWidgetForm elements based on queries to the database. 不幸的是,尽管进行了大量研究和搜索,但我还没有找到一种基于对数据库查询生成sfWidgetForm元素的方法。
I'll outline what the purpose of this is by explaining the flow of the project. 我将通过解释项目流程来概述其目的。
What I'm most interested in here is data on dynamically building forms within Symfony. 我在这里最感兴趣的是有关在Symfony中动态构建表单的数据。 I can build using a component easily, but I don't really want to. 我可以轻松地使用组件进行构建,但是我真的不想要。 Especially since I plan to quit soon, and keeping something within the framework would be ideal for my team mates. 特别是因为我计划很快退出,并且在框架内保留一些内容对于我的队友来说是理想的选择。
Thanks for any ideas! 感谢您的任何想法! This is a pretty exciting project, despite being boring from the outside - I've never dynamically generated forms before, let alone within Symfony. 尽管从外面很无聊,这是一个非常令人兴奋的项目-我以前从未动态生成过表格,更不用说在Symfony中了。 Should be cool. 应该很酷。
You can certainly build selection lists / radio buttons / check boxes based on query - im not sure if this is exactly what you want to do ? 您当然可以根据查询建立选择列表/单选按钮/复选框-我不确定这是否正是您想要的?
See http://www.symfony-project.org/api/1_4/sfWidgetFormDoctrineChoice and the query
parameter - I use this a lot and it works fine. 请参阅http://www.symfony-project.org/api/1_4/sfWidgetFormDoctrineChoice和query
参数-我经常使用它并且效果很好。
To build a whole form dynamically is going to be difficult IMO - I think you need to define at least some rules so that you can display / hide certain form elements. 动态创建整个表单将非常困难IMO-我认为您至少需要定义一些规则,以便可以显示/隐藏某些表单元素。
A functioning example of how I solved this problem can be found here: http://pastebin.com/NrJeADAk 有关如何解决此问题的功能示例,请参见: http : //pastebin.com/NrJeADAk
It works well. 它运作良好。 If your database describe your forms properly and consistently, you can even create new forms by submitting their descriptions via a form. 如果您的数据库正确且一致地描述了表单,则您甚至可以通过通过表单提交其描述来创建新表单。 I've done this for my team at work, and with very heavy validation on the fields, so far they haven't managed to create a single form that causes issues. 我已经为团队工作完成了此任务,并且在现场进行了大量的验证,到目前为止,他们还没有设法创建导致问题的单一表单。 I'm a frequent SO user, so if you stumble across this and would like to know more, feel free to message me. 我经常使用SO,因此如果您偶然发现此问题并想了解更多信息,请随时给我发消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.