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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:10:11+00:00 2026-05-15T05:10:11+00:00

I’m about to write a admin panel for my CMS written in CodeIgniter. There

  • 0

I’m about to write a admin panel for my CMS written in CodeIgniter. There will be some user information visible at all time – both in the layout’s header section and the sidebar. I’m used to do it in a way that I personally hope and think could be done a lot easier, since I’m tired of sending the same parametres to the view over and over again, when it’s dynamic data that needs to be displayed on every page anyways (such as unread messages, username, name, status, etc).

I’ll need controllers and models, I know that, but do I have to pass, just for an example, the user’s username, unread messages etc. every time I need to load a view? Should I do some kind of library for this?

Now my question is: How would I do it when it comes to best practice and for making it easy to maintain in the future?

I hope my question is understandable 🙂

  • 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-15T05:10:12+00:00Added an answer on May 15, 2026 at 5:10 am

    Personally, I would extend the Controller library (create a MY_Controller by following the guidance at the bottom of Creating Libraries at codeigniter.com).

    You would use your model etc as normal. Then you would create a private function in your MY_Controller class to get the relevant “global” data and call

    $this->load->vars('everywhere_data', $data_from_relevant_models);
    

    which would make the data available to all views called from that point on as $everywhere_data. Then add a reference to that function in the constructor of MY_Controller, perhaps with a conditional checking for the user to be actually logged in.

    If it’s complex to collect and get all that data, you might write a library to handle it for you, but the ‘controller’ part would still be done by MY_Controller: i.e. to get the data and then use load->vars() to publish it to the view.

    As a quick and untested example, MY_Controller would start something like as follows:

    <?php
    class MY_Controller extends Controller
    {
        private $logged_in_user;
    
    
        function MY_Controller()
        {
            parent::Controller();
    
            if( $this->_logged_in_userid() > 0 )
            {   
                $this->logged_in_user = $this->_get_user( $this->logged_in_userid() );
    
                $this->load->vars('logged_in_username', $this->logged_in_user->username );
            } else {
                $this->logged_in_user = false;
            }
    
        }
    ...
    }
    

    Note that things like _logged_in_userid() would access the session for you (e.g. return $this->session->userdata('logged_in_userid');), and _get_user() would access the relevant models.

    Finally, you would have a view that accesses $logged_in_username (or everywhere_data in my first example) which you would call into your headers etc. This leaves your normal controllers uncluttered so that they can focus on delivering their specific functionality, stops you rewriting your code several times AND maintains the MVC ideals.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article

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.