Skip to content

Instantly share code, notes, and snippets.

@pujie
Created July 5, 2011 09:07
Show Gist options
  • Save pujie/1064525 to your computer and use it in GitHub Desktop.
Save pujie/1064525 to your computer and use it in GitHub Desktop.
menu library for codeigniter
/*
add this to your config.php
*/
$config['css']='css_style.css';
h1{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:30px;
}
h2{
background: silver;
}
p{
font-family:Georgia, "Times New Roman", Times, serif;
font-size:12px;
}
#footer{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
}
#menutable{
color: gold;
border: 1px solid gold;
}
.menuitem{
display: none;
position: absolute;
list-style-type:none;
margin-top:0px;
padding-left:0px;
background: blue;
color:whitesmoke;
width: 100px;
}
.menuitem li:hover {
background: gold;
color: blue;
}
.menuheader :hover .menuitem{
display: block
}
<?php
/*place this in Model folder*/
class General extends CI_Model{
function __construct(){
parent::__construct();
$this->load->helper('url');
$this->load->library('menu/menu_lib');
}
function setpage($title){
$menu=new Menu_lib;
$tmp=anchor('Help/about','About');
$hdr = new Menu_header;
$chd['satu']='';
$prd['index']='Index';$prd['Add']='Add Product';
$clt['index']='Index';$clt['Add']='Add Client';
$abt['index']='Index';$abt['faq']='F.A.Q';$abt['About']='About';
$menu_header['1']=$hdr->accept_param('Home/index','Home',$chd);
$menu_header['2']=$hdr->accept_param('Product/index','Product',$prd);
$menu_header['3']=$hdr->accept_param('Client/index','Client',$clt);
$menu_header['4']=$hdr->accept_param('Help/index','Help',$abt);
$data['menu']=$menu->show_menu($menu_header);
$data['header']="<div>PHP Menu Header</div>";
$data['footer']="<div>PHP Menu Footer</div>";
$data['standard_css']='<link rel="stylesheet" type="text/css" href=' . $this->config->item('base_url') . '/' . $this->config->item('css') . '>';
$data['title']='<h1>' .$title . '</h1>';
$data['css']=$this->config->item('css');
$data['base']=$this->config->item('base_url');
return $data;
}
}
<?php
/*place this in controller folder*/
class home extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->library('menu_lib');
$this->load->model('general');
}
function index(){
$data=$this->general->setpage('Home Index Title');
$this->load->view('home/index',$data);
}
function test(){
$menu=new Menu_lib;
$data['menu']=$menu->show_menu();
$this->load->view('home/test',$data);
}
}
<?php
echo $standard_css;
echo $header;
echo $menu;
echo $title;
echo $footer;
<?php
/*place this in libraries folder*/
class Menu_header{
function accept_param($url_path, $menu_text, $item_array){
$menu = '<td class="menuheader">';
$menu .= anchor($url_path, $menu_text . $this->menu_item($item_array));
$menu .= '</td>';
return $menu;
}
function menu_item($param){
$item = '<ul class=menuitem>';
foreach($param as $par){
$item .= '<li>' . $par . '</li>';
}
$item .= '</ul>';
return $item;
}
}
<?php
/*place this in libraries folder*/
class Menu_lib {
function __construct()
{
$object = & get_instance();
$object->load->helper('url');
$object->load->library('table');
$object->load->library('menu/menu_header');
}
function show_menu($menus){
$hdr = new Menu_header;
$menu = "<table id='menutable'>";
$menu .= "<tr>";
foreach($menus as $mn){
$menu .= $mn;
}
$menu .= "</tr>";
$menu .= "</table>";
return $menu;
}
}
<?php
/*place this in controller folder*/
class Product extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->helper('form');
$this->load->library('menu/menu_lib');
$this->load->model('general');
}
function index(){
$menu=new Menu_lib;
$data=$this->general->setpage('Product Index');
$this->load->view('product/index',$data);
}
function add(){
$menu=new Menu_lib;
$data['menu']=$menu->show_menu();
$this->load->view('product/add',$data);
}
}
<?php
/*place this in your view/home/ folder */
$this->load->view('share/header');
echo $menu;?>
<h2>this is a test page</h2>
<?php
$this->load->view('share/footer');
?>
@pujie
Copy link
Author

pujie commented Jul 5, 2011

This is a php menu library for CodeIgniter framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment