Skip to content

davicotico/php-quick-menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Quick Menu

Esta clase PHP permite crear un menu Html a partir de una string Json. Por favor califica este repositorio, pues de esa forma voy a saber que este trabajo está siendo útil. La clase tiene parámetros de configuración, explicados en este tutorial: http://codeignitertutoriales.com/php-menu-dinamico-multinivel/

Yes

Input

[{	"text": "Home",	"href": "#home",	"title": "Home" }, {	"text": "About",	"href": "#",	"title": "About",	"children": [{	"text": "Action",	"href": "#action",	"title": "Action"	}, {	"text": "Another action",	"href": "#another",	"title": "Another action"	}] }, {	"text": "Something else here",	"href": "#something",	"title": "Something else here" }] 

Output

<ul class="nav navbar-nav" id="#myMenu"> <li><a href="#home" title="Home">Home</a></li> <li class="dropdown"> <a href="#" title="About" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">About <i class="caret"></i></a> <ul class="dropdown-menu"> <li><a href="#action" title="Action">Action</a></li> <li><a href="#another" title="Another action">Another action</a></li> </ul> </li> <li><a href="#something" title="Something else here">Something else here</a></li> </ul>

How to use

  • Extend the QuickMenu class for customization. For instance Bootstrap menu. (This is optional)
require 'QuickMenu.php'; class BootstrapMenu extends QuickMenu { public function __construct($options = array()) { parent::__construct($options); $this->set('dropdownIcon', '<i class="caret"></i>'); $this->set('ul-root', array('class'=>'nav navbar-nav', 'id'=>'#myMenu')); $this->set('ul', array('class'=>'dropdown-menu')); $this->set('li-parent', array('class'=>'dropdown')); $this->set('a-parent', array('class'=>"dropdown-toggle", 'data-toggle'=>"dropdown", 'role'=>"button", 'aria-haspopup'=>"true", 'aria-expanded'=>"false")); } }
  • Include your class
include "BootstrapMenu.php"; $str = '[{"text":"Home", "href": "#home", "title": "Home"}, {"text":"About", "href": "#", "title": "About", "children": [{"text":"Action", "href": "#action", "title": "Action"}, {"text":"Another action", "href": "#another", "title": "Another action"}]}, {"text":"Something else here", "href": "#something", "title": "Something else here"}]';
  • Instance the class with data parameters
$qMenu = new BootstrapMenu(array('data'=>$str));
  • Use the methods availables
$qMenu->setActiveItem('http://codeignitertutoriales.com'); $qMenu->insert(array("text"=>'Ooh!', "href"=>'http://codeignitertutoriales.com', "title"=>'Awesome'), 'Another action', 'About'); $qMenu->insert(array("text"=>'Ultimo item', "href"=>'https://github.com/davicotico', "title"=>'My Github'));
  • Renderize the menu in a string variable
$menu = $qMenu->html();