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 1048511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:28:06+00:00 2026-05-16T16:28:06+00:00

So I have a menu that I want to generate a main menu based

  • 0

So I have a menu that I want to generate a main menu based on the authenticated user’s access level. No problem creating the menu, however I want to automatically create the generated menu in my “header” view. So in my controller I am calling the “header” view, but I don’t want to pass this dynamic part of the header like this:

$data['menu'] = 'Some Generated HTML Menu';
$this->load->view('header',$data);

I would rather it already be included in my header file, but I’m not exactly sure how to do this (aside from adding the $data declaration from inside of my constructor).

  • 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-05-16T16:28:07+00:00Added an answer on May 16, 2026 at 4:28 pm

    I don’t know if this will help you, but this was how I did my template system for the longest time before moving on to a more advanced method.

    Top Head: views/inc/top_head.php

    <html>
    <head>
    <!-- all of your imports you want across all pages -->
    

    Bottom Head: views/inc/bottom_head.php

    I do it this way so that I can split and add custom Javascript things and maybe bring in special case imports.

    </head>
    <body>
    <div id="main_container">
        <div id="navigation">
             <?php
                  // DO YOUR NAVIGATION MAGIC HERE
                  if($is_logged_in) :
                      // BAM MAGIC DONE
                  else :
                      // No magic show here
                  endif;
             ?>
        </div>
    

    Footer: views/inc/footer.php

    This is where you will put in your footer things etc….

    </div>
    </body>
    

    Now we are at the point that we need to actually fill content in to the template

    Index Page: /views/some_controller/index.php

    <?php $this->load->view('inc/top_head.php'); ?>
    
    <?php $this->load->view('inc/bottom_head.php;) ?>
    
    <h1>Hello</h1>
    <p>Some filler content and stuff I guess would go here...Of course</p>
    
    <?php $this->load->view('inc/footer.php'); ?>
    

    So there, we have a quick template system. Now to show you what I have done for a controller

    <?php
    
    class Some_Controller extends Controller {
        public $page_data;
    
        public function __construct() {
            parent::__construct();       // Load parent constructor
    
            // This is page data that we obviously don't want to keep retyping
            $this->page_data = array(
                'is_logged_in' => FALSE, // Obviously do some test here
                'page_title'   => 'Some Title'
            );
        }
    
        public function index() {
            $this->_load('some_controller/index');
        }
    
        /** Should think of a better name but meh */
        private function _load($view) {
            $this->load->view($view, $this->page_data);
        }
    }
    

    I hope this helped in some way or another. Mind you this is a quick write up. If I really wanted this to go into production, I would have moved the _load function into a parent class and extended it. I would also probably move the page_data variable along with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate a tree-based menu using Java that will appear on a
I have a menu div that I want to slide down so it's always
I have a menu of product brands that I want to split over 4
I have an asp:Menu and it contains a top level menu item that points
I have a Word 2003 .dot template that changes its menu based on the
I have a menu that let's a user select a country. Exactly like that
I have a jquery menu that has so many entries that it extends further
I have some markup for a popup menu that works in firefox but not
The background is I have a custom control that is a asp:Menu that is
I have a (derived) Menu control, that displays a rather large list of items

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.