hello i am new user of yii, i want create dropdown menu through database.
i had use cdropdownmenu extension, drop down menu is created, but it is only showing one root member and all members as child, i want make more parent member in menu, this is my database.
id;sort;parent;title
1; 0; 0; "root"
2; 0; 1; "First Entry"
3; 0; 1; "Second Entry withoud Childs"
4; 0; 1; "Third Entry"
5; 0; 3; "Child of the third Entry"
6; 0; 5; "Child of the Child of the third Entry"
7; 0; 1; "Child of the first Entry"
i had change parent value but it is not working.
this is my model code
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, 'Hierarchy', 'parent'),
'childs' => array(self::HAS_MANY, 'Hierarchy', 'parent', 'order' => 'sort ASC'),
);
}
public function getListed() {
$subitems = array();
if($this->childs) foreach($this->childs as $child) {
$subitems[] = $child->getListed();
}
$returnarray = array('label' => $this->title, 'url' => array('shop/view', 'id' => $this->id));
if($subitems != array())
$returnarray = array_merge($returnarray, array('items' => $subitems));
return $returnarray;
}
this is my main.php code to print menu item
$model = Hierarchy::model()->findByPk(1);
$items[] = $model->getListed(); // note that the [] is important, otherwise CMenu will crash.
$this->widget(‘application.extensions.CDropDownMenu.CDropDownMenu’,array(
'items'=>$items,
));