Yii framework extension which provides a multi-level responsive menu using Font Awesome
Requirements ¶
Tested with Yii 1.1.10 and 1.1.12. may work on other versions
Installation ¶
- Extract the file under protected/extensions folder.
Usage ¶
$this->widget('application.extensions.eflatmenu.EFlatMenu', array(
'items' => array(
array('label' => 'Home', 'url' => array('/site/index'), 'active' => true, 'icon-class'=>'fa-home'),
array('label' => 'About', 'url' => array('/site/page', 'view' => 'about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
array('label'=>'Level 2 Menu', 'url'=>'#', 'items' => array(
array('label' => 'Sub-Menu 1', 'url' => '#', 'icon-class'=>'fa-home'),
array('label' => 'Level 3 Menu', 'url' => '#', 'items' => array(
array('label' => 'Sub-Menu 1', 'url' => '#', 'icon-class'=>'fa-home'),
array('label' => 'Sub-Menu 2', 'url' => '#'),
)),
)),
array('label' => 'Login', 'url' => array('site/login'), 'visible' => Yii::app()->user->isGuest),
array('label' => 'Logout (' . Yii::app()->user->name . ')', 'url' => array('/site/logout'), 'visible' => !Yii::app()->user->isGuest)
)
));
Not registering js and css
To register the css and js correctly you will need to change public function init() to this and it will work. This is assumed you extracted it to your extensions folder. You can also delete the private items at the top too.
public function init() { parent::init(); $cs=Yii::app()->getClientScript(); $scriptUrl = Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.extensions.eflatmenu.resources')); $cs->registerCssFile($scriptUrl . '/eflatmenu.css'); $cs->registerCssFile($scriptUrl . '/font-awesome/font-awesome.css'); $cs->registerScriptFile($scriptUrl . '/eflatmenu.js'); }
@skworden
Updated the code as per @skworden suggestion.
@turi thanks for new update
thanks turi for time dedication to extension and support !
Not registering js and css
I downloaded the extension and was getting an error with font-awesome.css (not found). I took a look in the init function and found the cose skworden sugested, but it turns out that the path to font-awesome.css was '/font-awesome/css/font-awesome.css'. I changed de init function and it worked. I don't know if this is correct (I'm very new to Yii).
Thanks for this excelent extension!
@VictorG
Thanks for mentioning the error :)
The problem was with 'font-awesome.css' file path... which is fixed now.
Selected Links are not Showig selected.
Selected Links are not Showing selected.
If I click on login link and the page redirects, than Home link is showing as selected .
Any Solution for this.
Need to Add class to last menu item
Hello, I want the last menu item to extreme right hand side. but I cant add class/style/htmloptions.. How can I achieve it? Please help
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.