Yii dynamic menu creation jquery mobile -
i have set-up jquery mobile site , creating cms using yii framework.
i have database table set-up menu creation linked table page content.
the menu table has: id, title, parent, collapsible (collapsible checkbox used determine whether create page given menu item don't want collapsible items click-able can see jsfiddle below)
jsfiddle.net/gn7q6/
from jsfiddle above can see how want menu function.
i'm unsure of how create dynamic menu way.
i assume have setup model menu menutable , there has defined relation
public function relations() { return array( 'childmenuitems' => array(self::has_many, 'menu', 'parent_id'), ); }
getting top parent menus
// parent menu not have parent menu id (0, empty or null, case using comapare 0 default fk column value) $topmenus = menu::model()->findallbyattributes(array('parent_id' => '0'));
to render menu
<ul data-role="listview" data-inset="true"> <?php $render = ""; echo rendermenuitems(topmenus, &$render); }?> </ul>
the function handles recursive n-sub-menus rendering
<?php function rendermenuitems($parentitem, &$render){ if(count($parentitem->childmenuitems) > 0){ $render .= '<li class="custom-li"> <div data-role="collapsible" class="custom-collapsible2" data-iconpos="right"> <h3><?php echo $parentitem->title ?></h3> <ul data-role="listview">'; foreach($parentitem->childmenuitems $item){ $render .= rendermenuitems($parentitem,$render); } $render .= '</ul> </div> </li>'; } else{ $render .= '<li><a href="<?php echo $menu->actionurl ?>"><?php echo $menu->title ?></a></li>'; } return $render; } ?>
i did not debug yet, idea same. not menu, logic of many other menus same if there has repetition of layout structure on sub-level menu
Comments
Post a Comment