logo

This is an old version of this answer!

Return to the current answer
You can do it with sfWidgetFormChoice this way:
in form class:

$this->widgetSchema['template_id' = new sfWidgetFormChoice(array('choices' =>TemplateCategory::getChoices()));


in TemplateCategory class:

class TemplateCategory extends BaseTemplateCategory
{
public static function getChoices()
{
$result = array();
$treeObject = Doctrine::getTable('TemplateCategory')->getTree();
$rootColumnName = $treeObject->getAttribute('rootColumnName');

foreach ($treeObject->fetchRoots() as $root) {
$options = array(
'root_id' => $root->$rootColumnName
);
foreach($treeObject->fetchTree($options) as $node) {
$result['-' . $node->id] = str_repeat('-', $node->level) . ' ' . $node->name;
foreach ($node->templates as $tpl) {
$result[$tpl->id] = str_repeat('-', $node->level + 1) . ' ' . $tpl->name;
}
}
}
return $result;
}
}


the result should be as in attachment

attachment image View Attachment

Wojciech Sznapka | 05/13/10 at 4:09pm

This is an old version of this answer!

Return to the current answer