在Symfony 1.4中订购嵌入式表格

时间:2013-09-11 10:16:50

标签: php mysql symfony1 symfony-1.4

我正在尝试通过其中一个值在SF1.4后端模块中订购嵌入式表单。

$ this-> embedRelation('MyInnerForm as innerForm');

给我一​​个表格,显示MyInnerForm中所有条目的编辑表格。我希望它以正确的方式订购。找不到修改查询的方法来添加orderBy-Option或(更好)使用PHP对结果数组进行排序。谢谢你的建议。

1 个答案:

答案 0 :(得分:0)

查看embedRelation的代码:它只是获得您的关联,在其上运行foreach并致电embedForm

  $subForm = new sfForm();
  foreach ($this->getObject()->$relationName as $index => $childObject)
  {
    $form = $r->newInstanceArgs(array_merge(array($childObject), $formArgs));

    $subForm->embedForm($index, $form, $innerDecorator);
    $subForm->getWidgetSchema()->setLabel($index, (string) $childObject);
  }

  $this->embedForm($fieldName, $subForm, $decorator);

请参阅$this->getObject()->$relationName部分?没有选择订购嵌入表单,但您可以自己嵌入它们。

<?php
  foreach ($this->getObject()->getMyInnerFormOrderedByStuff() as $index => $childObject)
  {
    $form = new InnerFormForm($childObject); // todo!!

    $subForm->embedForm($index, $form, $innerDecorator);
    $subForm->getWidgetSchema()->setLabel($index, (string) $childObject);
  }

  $this->embedForm($fieldName, $subForm, $decorator);

你必须实施getMyInnerFormOrderedByStuff(),就是这样。