how can i create nested dropdown list using $form->dropDownList
I needed dropdown list structure as follows
listdata 1
listdata 1.1
listdata 1.1.1
listdata 1.1.2
listdata 1.2
listdata 1.2.1
listdata 2
listdata 2.1
listdata 2.1.1
listdata 2.2
(My actual requirement is when i am create new category of products it is sub category of another product )
pls give your valuable suggestion and example or link
The following code is working for two sub levels i need more than two levels of drop down list pls give the logic any body
// retrieve the parent categories first
$parents = RCategoriesDescription::model()->findAllByAttributes(array('parent_id'=>0));
// prepare an array to hold parent categories as optgroups, and their child categories as selectable items
$categories = array("Select a Category Below");
// prepare an array to hold the location of the selected item (if any)
$selectedItemInfo = array();
foreach($parents as $parent) {
// retrieve the sub categories for this parent category
$children = RCategoriesDescription::model()->findAllByAttributes(array('parent_id'=>$parent->categories_id));
// prepare an array to temporarily hold all sub categories for this parent category
$categoriesChildren = array();
$categoriesChildren[$parent->categories_id]=$parent->categories_name;
// iterate over sub categories
foreach($children as $child) {
// Assign the category name (label) to its numeric id
// Example. '10' => 'Coffee Mugs'
$categoriesChildren[$child->categories_id] = ' _ '.$child->categories_name;
if(isset($_GET['id']) && $child->categories_id == $_GET['id']){
// store the location of the current sub category
$selectedItemInfo[0] = $parent->categories_name;
$selectedItemInfo[1] = $child->categories_id;
}
}
// Example. 'Kitchenware' => {array}
//print_r($categories);exit;
$categories=array_merge($categories,$categoriesChildren);