How to call pages to menu(menu.php) in codeigniter

54 views
Skip to first unread message

New Learner

unread,
Nov 2, 2012, 1:38:34 AM11/2/12
to codei...@googlegroups.com
Hi to all,
i hope all have good day,

I am a new to codeigniter, Some body tell me how to call (or) pull pages in view To menu in code Igniter

Here is my code  like
---------------------------------------
pages.php(controller)
---------------------------------------

<?php

class Pages extends CI_Controller 
{

    public function view($page = 'home')
    {
        if(!file_exists( APPPATH . 'views/pages/'.$page.'.php'))
        {
            //whoops we don't have a page for that!
            show_404();
        }

        $data['title'] = ucfirst($page); //Capitalize the first letter
        $this->load->view('templates/header', $data);
        $this->load->view('templates/menu', $data);
        $this->load->view('pages/'.$page, $data);
        $this->load->view('templates/footer', $data);
    }
}
?>

My view pages are  home.php , contact.php , about.php

I wish to display in horizontal menu  dynamically.

Thanks if any suggestions....

Eughenio Constantino

unread,
Jun 9, 2013, 10:16:12 AM6/9/13
to nagender.g...@gmail.com, codei...@googlegroups.com
Hello,

You can call the MENU the same way you already called the others or inside one of these views with the $this->load->view('YOUR_TEMPLATE');....

Best,
--
Eughenio Constantino
--------------------------------
Message has been deleted

Eduardo Mattos

unread,
Feb 25, 2016, 9:44:59 AM2/25/16
to codeigniter
I suggest you to change the way you are calling your views:

You should use a controller named as the page you want: e.g: your controller should be named "home", then in your application the URL will be site.com.br/home, instead of site.com.br/pages/home.

So, in the index function of this controller you should put something like:

public function index(){
    $this->data['view'] = 'home/index';
    $this->load->view('includes/header', $this->data);
}

In the view includes/header you have your menu and all stuff you will load in all the pages and a call $this->load->view($view);

It will load your header, and inside the header will load another view.

Thats the right way,
I hope i've helped
Reply all
Reply to author
Forward
0 new messages