Symfony 动态模型表单模板
我正在开发基于 symfony 的网络应用程序。我有很多模型(笔记本电脑、上网本、Ipad、平板电脑...所有这些模型继承自产品模型)。基于这些模型我还有表单(LaptopForm、NetbookForm...等等) 。 在我的操作类中,我获取模型名称并将其分配给模板:
$modelForm = $this->modelName.'Form';
$this->form = new $modelForm();
然后在我的模板中我执行 ..打印所有字段和标签没有问题在 html 表中。
但我的问题是我想将模板分为两部分。常规和特殊字段集。在常规字段集中,我想显示产品模型字段(名称,价格...)。但是特殊字段集根据产品类型而变化。我如何处理这个特殊字段集?有人可以提供线索或来源吗?
提前致谢!
I am developing symfony based web application. I have many Models (Laptop, Netbook, Ipad,Tablet.... all these models inherited from Product model).Based on these models I also have Forms (LaptopForm, NetbookForm...so on).
In my action class I get Model name and assign it to template :
$modelForm = $this->modelName.'Form';
$this->form = new $modelForm();
Then in my template I do that <?php echo $form ?>
..There is no problem it prints all fields and labels in html table.
But my problem is that I want to divide template in to 2 parts. General and special fieldset.In general fields set i want to display Product model fields(name,price...).But Special field set changes according to product type. How I can handle this special fields set?Can someone give a clue or source please?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在专门的表单类中手动管理它(不更改基类)。
也许,通过使用 sfWidgetFormSchema :
http://www.symfony-project.org/forms/1_4 /en/A-Widgets#chapter_a_sfwidgetformschema
您必须将小部件命名为“常规”和“特殊”,以便在表单模板中重复使用,如下所示:
You can manage it manually, in your specialized form class (not alter the base class).
Perhaps, with the use of sfWidgetFormSchema :
http://www.symfony-project.org/forms/1_4/en/A-Widgets#chapter_a_sfwidgetformschema
You have to name the widget 'general' and 'special', for a stanhdard re-use in form template, like this :