CREATING A SIMPLE MENU LIBRARY IN CODEIGNITER

MY CLASS: /application/libraries/mymenu.php

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Mymenu {

function show_menu(){
$CI = &get_instance();
$CI->load->helper(‘url’);
$menu = “<ul>”;
$menu .= “<li>”;
$menu .= anchor(“books/main”,”List of Books”);
$menu .= “</li>”;
$menu .= “<li>”;
$menu .= anchor(“books/input”,”Input Book”);
$menu .= “</li>”;
$menu .= “</ul>”;
return $menu;
}
}

CONTROLLER: books.php

<?php

class Books extends CI_Controller {

function __construct() {
parent::__construct();
$this->load->library(‘mymenu’);
}

function main(){
$data[‘menu’] = $this->mymenu->show_menu();
$this->load->view(‘books_main’,$data);
}

function input(){
$data[‘menu’] = $this->mymenu->show_menu();
$this->load->view(‘books_input’,$data);
}
};

VIEWS:

books_menu.php
books_main.php
books_input.php
put this inside:

enjoy!!!

SOURCE: http://www.phpeveryday.com/articles/CodeIgniter-Form-Creating-Menu-Library-P230.html

Advertisements
This entry was posted in CODE IGNITER. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s