sfWidgetFormDoctrineChoice:如何从嵌套模型迭代数据? (交响乐1.4)
我的 ConnectForm 带有来自其他模型的嵌套字段:Numbers。 时一切正常,
<?php echo $form['numbers_list'] ?>
我想用所有数字渲染此 ConnectForm,并且当我只是但我需要打印其他 Numberss 字段 例如:价格、代码等。 如何打印呢?
对我来说最好的方法是这样的:
<?php foreach($form['numbers_list'] as $num): ?>
<span> echo $num->renderInput()</span>
<span>echo $num->getPrice()</span>
<span>echo $num->getCode()</span>
<?php endforeach; ?>
I have the ConnectForm with nested fields from other model: Numbers.
I want to render this ConnectForm with all Numbers and everything works well when i just
<?php echo $form['numbers_list'] ?>
But i need to print other Numberss' fields like: price, code etc.
How to print it?
The best way for me would something like this:
<?php foreach($form['numbers_list'] as $num): ?>
<span> echo $num->renderInput()</span>
<span>echo $num->getPrice()</span>
<span>echo $num->getCode()</span>
<?php endforeach; ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能最好创建一个自定义 sfWidgetFormSchemaFormatter 类,然后使用它来输出您的表单 - 一旦您创建了新的 sfWidgetFormSchemaFormatter 类,您就可以通过执行
例如:
然后在表单的配置方法中添加以下内容,告诉表单使用您的自定义装饰器:
$this->getWidgetSchema()->setFormFormatterName('custom');
You probably are better off creating a custom sfWidgetFormSchemaFormatter class and then using that to output your form - you can output a whole form once you have created your new sfWidgetFormSchemaFormatter class by doing
<?php echo $form ?>
for example :Then within the configure method of your form add the following that tells the form to use your custom decorator :
$this->getWidgetSchema()->setFormFormatterName('custom');