Hello! I totaly confused after i read this articles
nestedset http://www.yiiframework.com/extension/nestedset/
http://www.yiiframework.com/doc/cookbook/61/
and now i want to understant, how to create array for CTreeView or DropDownList from this hierarchical structure ?
i have table
CREATE TABLE IF NOT EXISTS `Place` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sort` int(11) NOT NULL,
`parent` int(11) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
And model Place.php with this functions
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'getparent' => array(self::BELONGS_TO, 'Place', 'parent'),
'childs' => array(self::HAS_MANY, 'Place', 'parent', 'order' => 'sort ASC'),
);
}
I understand this thing -
Parent name of this id = 7
$model = Place::model()->findByPk(7);
$parent = $model->getparent;
echo $parent->title;
All childrens from pk1
$model = Place::model()->findByPk(1);
foreach ($model->childs as $child)
{
echo '<br />'.$child->title;
}
But i need to create array, that will work with my widgets, like this
$this->widget('CTreeView', array('data' => $items));
or some widgets dropdownlists …
I dont know how =(((
IS there any decisions ?
thanx…
ps Sory for english…