我在爲NestedSet結構呈現sfWidgetFormDoctrineChoice(複選框集)小部件時遇到困難。sfWidgetFormDoctrineChoice for NestedSet模型
class ModelForm extends BaseModelForm
{
public function configure()
{
$this->setWidget('relatedmodel_list', new sfWidgetFormDoctrineChoice(array(
'expanded' => true,
'multiple' => true,
'model' => 'Relatedmodel',
'table_method' => 'fetchTree'
)));
}
}
class RelatedmodelTable extends Doctrine_Table
{
/**
* Gets tree elements in one query (one root only)
*/
public function fetchTree()
{
$q = $this->createQuery('m')
->addOrderBy('m.lft');
$tree = $q->execute(array(), Doctrine_Core::HYDRATE_RECORD_HIERARCHY);
return $tree;
}
}
現在,如果我只是呈現形式是這樣的:<?php echo $form['relatedmodel_list'] ?>
它只能顯示錶單控件(複選框)對我的層次結構的第一級別的元素。
我找,讓我來遍歷控件的選擇我會遍歷集合的方式實現:
<?php foreach ($form['relatedmodel_list'] as $widget): ?>
<?php echo $widget->render() ?>
<?php foreach ($widget->getChildren() as $child_widget): ?>
<?php echo $child_widget->render() ?>
<?php endforeach; ?>
<?php endforeach; ?>
我真的不希望我的呈現形式,一個命令。我需要遍歷選項和他們的孩子。 – Dziamid