sfWidgetFormDoctrineChoice:如何从嵌套模型迭代数据? (交响乐1.4)

发布于 2024-12-09 03:32:08 字数 516 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜扑 2024-12-16 03:32:08

您可能最好创建一个自定义 sfWidgetFormSchemaFormatter 类,然后使用它来输出您的表单 - 一旦您创建了新的 sfWidgetFormSchemaFormatter 类,您就可以通过执行 例如:

class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
  protected
    $rowFormat       = "<span class=\"my-label-class\">%label%</span>\n  <span>%error%%field%%help%%hidden_fields%</span>`n",
    $errorRowFormat  = "<span class=\"my-error-class\" colspan=\"2\">\n%errors%</span>\n",
    $helpFormat      = '<br />%help%',
    $decoratorFormat = "<div>\n  %content%</div>";
}

然后在表单的配置方法中添加以下内容,告诉表单使用您的自定义装饰器:

$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 :

class sfWidgetFormSchemaFormatterCustom extends sfWidgetFormSchemaFormatter
{
  protected
    $rowFormat       = "<span class=\"my-label-class\">%label%</span>\n  <span>%error%%field%%help%%hidden_fields%</span>`n",
    $errorRowFormat  = "<span class=\"my-error-class\" colspan=\"2\">\n%errors%</span>\n",
    $helpFormat      = '<br />%help%',
    $decoratorFormat = "<div>\n  %content%</div>";
}

Then within the configure method of your form add the following that tells the form to use your custom decorator :

$this->getWidgetSchema()->setFormFormatterName('custom');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文