powers
(Amohamed86)
August 7, 2012, 9:41am
1
How can I make the drop down list automatically gather all my models. So for example if I click on one of my Menu items "Products" I want all the products model to show on the drop down. I have seen a few extensions that supports drop down menus but nothing about gathering the list from models table.
I also need to be able to use images for the main menu items.
I’m slightly reluctant to start this because I always find a wiki or extension for this type of thing half way through. Can anyone direct me to an extension or possibly give me good guidelines?
Thanks
Newb
(Antowka2010)
August 7, 2012, 10:57am
2
I think you have two ways to do it, preload and show/hide models, or ajax calls. I saw some tutorial about dependent dropdowns, it may help you.
powers
(Amohamed86)
August 7, 2012, 11:55am
3
Newb:
I think you have two ways to do it, preload and show/hide models, or ajax calls. I saw some tutorial about dependent dropdowns, it may help you.
There is this following extension that provides drop down menus but how I would I load the $models? how do I implement models into the sub menus?
<?php $this->widget('application.extensions.mbmenu.MbMenu',array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Contact', 'url'=>array('/site/contact'),
'items'=>array(
array('label'=>'sub 1 contact'),
array('label'=>'sub 2 contact'),
),
),
array('label'=>'Test',
'items'=>array(
array('label'=>'Sub 1', 'url'=>array('/site/page','view'=>'sub1')),
array('label'=>'Sub 2',
'items'=>array(
array('label'=>'Sub sub 1', 'url'=>array('/site/page','view'=>'subsub1')),
array('label'=>'Sub sub 2', 'url'=>array('/site/page','view'=>'subsub2')),
),
),
),
),
),
)); ?>
Thanks
abennouna
(Abennouna)
August 7, 2012, 12:04pm
4
Hi. Have you tried to loop through your model values and build the relevant submenu ‘items’ array?
powers
(Amohamed86)
August 8, 2012, 10:27am
5
Hi
So I can loop through my Models like so
for ($i=0; $i<=100; $i++){
$cat= ECCategory::model()->findByPk($i);
echo ($cat==null) ? null : CHtml::link(CHtml::encode( $cat->Name), array('ECCategory/view', 'id'=>$cat->ID)).'<br/>';
}
That’s as far as I can go, not sure how to build the relevant submenu ‘items’ array. How do I place that code inside my submenus? I tried something like this but that obviously wasn’t successful
'items'=>array(
array('label'=>'Sub 1', 'url'=>array('/site/page','view'=>'sub1')),
array(
for ($i=0; $i<=100; $i++)
$cat= ECCategory::model()->findByPk($i);
echo ($cat==null) ? null : CHtml::link(CHtml::encode( $cat->Name), array('ECCategory/view', 'id'=>$cat->ID)),
),
),
Cheers
abennouna
(Abennouna)
August 8, 2012, 4:01pm
6
Well I was thinking more like this:
$items = array();
foreach ($models as $model)
$items[] = array('label' => $model->someAttribute, 'url' => …);
$this->widget('application.extensions.mbmenu.MbMenu',array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Contact', 'url'=>array('/site/contact'),
'items'=>array(
array('label'=>'sub 1 contact'),
array('label'=>'sub 2 contact'),
),
),
array('label'=>'Test',
'items'=>array(
array('label'=>'Sub 1', 'url'=>array('/site/page','view'=>'sub1')),
array('label'=>'Automatic generation from Model',
'items' => $items,
),
),
),
),
)); ?>
powers
(Amohamed86)
August 11, 2012, 10:05am
7
Well I was thinking more like this:
$items = array();
foreach ($models as $model)
$items[] = array('label' => $model->someAttribute, 'url' => …);
$this->widget('application.extensions.mbmenu.MbMenu',array(
'items'=>array(
array('label'=>'Home', 'url'=>array('/site/index')),
array('label'=>'Contact', 'url'=>array('/site/contact'),
'items'=>array(
array('label'=>'sub 1 contact'),
array('label'=>'sub 2 contact'),
),
),
array('label'=>'Test',
'items'=>array(
array('label'=>'Sub 1', 'url'=>array('/site/page','view'=>'sub1')),
array('label'=>'Automatic generation from Model',
'items' => $items,
),
),
),
),
)); ?>
Thanks Again Ben, your code was almost perfect just added 2-3 words to go past non-objects in my model. Also I put a limit too so I opted for the old skool for loop
$items = array();
for ($i=0; $i<=100; $i++){
$model = ECCategory::model()->findByPk($i);
//foreach ($models as $model)
($model==null) ? null : $items[] = array('label' => $model->Name, 'url' => array('view', 'id'=>$model->ID));
}
Appreciate your help
jagur2012
(Dedijagur)
October 27, 2012, 4:50am
8
Hi guys I have a coding like this, how to create in mbmenu extension
$menuArray = array(array(‘label’ => ‘Home’, ‘url’ => array(’/site/index’)));
if(Yii::app()->user->checkAccess('menuKecamatan')){
array_push($menuArray,array('label' => 'Kecamatan', 'url' => array('/kecamatan/kecamatan/admin')));
}
if(Yii::app()->user->checkAccess('menuDesa')){
array_push($menuArray,array('label' => 'Desa', 'url' => array('/desa/desa/admin')));
}
if(Yii::app()->user->checkAccess('menuBidang')){
array_push($menuArray,array('label' => 'Bidang', 'url' => array('/bidang/bidang/admin')));
}
if(Yii::app()->user->checkAccess('menuKategori')){
array_push($menuArray,array('label' => 'Kategori', 'url' => array('/kategori/kategori/admin')));
}
if(Yii::app()->user->checkAccess('menuJenis')){
array_push($menuArray,array('label' => 'Jenis', 'url' =>array('/jenis/jenis/admin')));
}
if(Yii::app()->user->checkAccess('menuKolom')){
array_push($menuArray,array('label' => 'Table', 'url' => array('/table/table/admin')));
}
if(Yii::app()->user->checkAccess('menuUserManager')){
array_push($menuArray,array('label' => 'User Manager', 'url' => Yii::app()->urlManager->createUrl('/userManager/user/admin')));
}
if(Yii::app()->user->checkAccess('menuAksesManajer')){
array_push($menuArray,array('label' => 'Akses Manajer', 'url' => Yii::app()->urlManager->createUrl('/aksesManajer/aksesManajer/aksesManajer')));
}
$menu = $menuArray;
$this->widget(‘application.extensions.mbmenu.MbMenu’, array(
'items' => $menu2));
abennouna
(Abennouna)
October 27, 2012, 6:29pm
9
@jagur2012
So what’s the issue you are facing with this code?
PS Where have you defined $menu2?