Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:49:34+00:00 2026-06-08T19:49:34+00:00

I am a newbie with codeigniter. I am trying to write an application using

  • 0

I am a newbie with codeigniter. I am trying to write an application using mysql database.
In my site I want to use menu as :

+Homepage
+About
+Services
  +Education services
  +neurofeedback
  +biofeedback

I need some information to understand. I use pages controller as main pages controller:

<?php 

class Pages extends CI_Controller {

        public function view($page = 'home')
        {$this->load->view('templates/header', $data);
        $this->load->view('pages/'.$page, $data);
        $this->load->view('templates/footer', $data);

my questions are :

1) where the menu controller must be coded inside pages controller or seperate one?

2) how can i make the menu controller from database ?

3) How can i make relation with the menu id and the page id?

I made lots of research but i need a little bit more understanding .

Thank you for your help.

Edit :
I have used MY_Controller as you say .

This is my pages controller :

class Home extends MY_Controller {
         function __construct() {
    parent::__construct();
  }

        public function view($page = 'home')
        {
         $this->load->helper('text');
            $data['records']= $this->services_model->getAll();
            if ( ! file_exists('application/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('pages/'.$page, $data);


        }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:49:36+00:00Added an answer on June 8, 2026 at 7:49 pm

    where the menu controller must be coded inside pages controller or seperate one?

    Assuming that you have a template that must be followed by all pages, I suggest you to do this.

    1. Create a basic controller

    In the ./application/core/ folder, create a file called MY_Controller

    class MY_Controller extends CI_Controller {
    
      protected $data = array();
    
      function __construct() {
        parent::__construct();
      }
    
      function render_page($view) {
        //do this to don't repeat in all controllers...
        $this->load->view('templates/header', $this->data);
        //menu_data must contain the structure of the menu...
        //you can populate it from database or helper
        $this->load->view('templates/menu', $menu_data);
        $this->load->view($view, $this->data);
        $this->load->view('templates/footer', $this->data);
      }
    
    }
    

    2. Create one controller to each page and use MY_Controller instead of CI_Controller

    class Homepage extends MY_Controller {
      function __construct() {
        parent::__construct();
      }
    
      function index() {
        //define data that the view can access
        $this->data['someDataToView'] = 'Some data';
        $this->render_page('pages/homepage');
      }
    
    }
    

    how can i make the menu controller from database?

    Well, you will not have a controller for the menu, but a view instead.

    Possibilities to the menu

    1. Create a view for the menu, load the records from the database in MY_Controller, load the view in render_page();
    2. Create a view for the menu, create a Helper function that defines the menu structure and use in MY_Controller, load the view in render_page();

    Example of menu template (adjust for your scenario):

    ./application/views/templates/menu.php

    <ul>
    <?php foreach($menus as $menu): ?>
      <li><a href='<?php print $menu["url"] ?>'><?php print $menu["title"] ?></a></li>
    <?php endforeach; ?>
    </ul>
    

    edit

    Given your Home controller, I think the error is in your file_exists check. See the Home controller that I change:

    class Home extends MY_Controller {
      function __construct() {
        parent::__construct();
      }
    
       public function view($page = 'home') {
         $this->load->helper('text');
         //always use $this->data
         $this->data['records']= $this->services_model->getAll();
         if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
         {
           //check the content of APPPATH.'views/pages/'.$page.'.php'
           // Whoops, we don't have a page for that!
           show_404();
         }
    
         $this->data['title'] = ucfirst($page); // Capitalize the first letter
    
         //if you use the MY_Controller, check the render_page function...
         //$this->load->view('pages/'.$page, $data);
         $this->render_page('pages/'.$page)
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie C++ programmer here. I'm trying to write a command line application that takes
Newbie here. I'm using codeigniter and mysql How can I dynamically (number of names
I am a newbie in codeigniter. I am using an an login form to
Newbie question. I am trying to use ActiveRecord::Base.connection.execute(..) in a ruby 3.1 app and
I am newbie. I have Windows XP and use the CodeIgniter framework. I wanted
I am about to start writing my first big CodeIgniter application, but before I
I am a newbie in codeigniter. I want to load jquery on every page.
I'm a newbie implementing OOP in PHP. For PHP project, I often use codeigniter
Newbie to LINQ, and trying to write the following query... select f.Section_ID, f.Page_ID, f.SortOrder,
I'm trying to implement an ORM in a CodeIgniter application, but cannot get it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.