xmlmenu Build your Menu from a Xml File instead of hard coded.

  1. Requirements
  2. Installation
  3. Usage
  4. Hints
  5. Multi Level Navigation

Build your Menu from a Xml File instead of hard coded in your layout/main.php.

Requirements

Yii 1.1 or above

Installation

Move XmlMenu.php File in your applications components folder (default: protected/components).

Usage

[layout/main.php]
$container = new XmlMenu('menu.xml');
$this->widget(
  'zii.widgets.CMenu', array(
    'items'=>$container->getData()
));


[menu.xml]

<?xml version="1.0" encoding="utf-8" ?>
<items>
  <item>
     <label>login</label>
     <url>array('site/login');</url>
     <visible>Yii::app()->user->isGuest;</visible>
  </item>
  <item>
      <label>Contact</label>
      <url>array('site/contact');</url>
  </item>
  <item>
     <label>Logout</label>
     <url>array('site/logout');</url>
     <visible>!Yii::app()->user->isGuest;</visible>
  </item>
</items>

Hints

/protected/config is a good place for storing XmlMenu files.

$container new XmlMenu(Yii::app()->basePath.'/config/menu.xml');

Multi Level Navigation

It's even possible to create multiple Levels of Navigation. Just insert another 'items' in the 'item'. :)

[multimenu.xml]

<?xml version="1.0" encoding="utf-8" ?>
<items>
  <item>
     <label>top</label>
     <url>array('site/login');</url>
     <visible>Yii::app()->user->isGuest;</visible>
     <items>
      <item>
         <label>sub1</label>
         ....
      </item>
      <item>
         <label>sub2</label>
         .......
      </item>
     </items>
  </item>
  <item>
      <label>Contact</label>
      <url>array('site/contact');</url>
  </item>
  <item>
     <label>Logout</label>
     <url>array('site/logout');</url>
     <visible>!Yii::app()->user->isGuest;</visible>
  </item>
</items>


10 1
8 followers
1 071 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: speedyfw
Created on: Aug 18, 2011
Last updated: 6 years ago

Downloads

show all

Related Extensions