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

  • Home
  • SEARCH
  • 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 8229053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:40:13+00:00 2026-06-07T16:40:13+00:00

I have been looking at CodeIgniter template systems and all so far, it allows

  • 0

I have been looking at CodeIgniter template systems and all so far, it allows you to change content within the header or footer file, but I am looking for a way to load data in to the header file from a model automatically (dependent on the template).

For example, in my header, it displays the users username and inbox. I need to load the users unread messages from a model and the users username. This is dependent on the template though – I only want to load that information if the user is logged in.

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

    Passing data from model to a view is not a good practice.

    You should pass data first to the controller and only then to your view.

    http://codeigniter.com/user_guide/overview/appflow.html

    As you can see on this application flow chart – there is no straight line between model and view.

    If you are interested in displaying model data in your “layout” – use hooks!

    http://codeigniter.com/user_guide/general/hooks.html

    Define a “pre_controller” hook, get CI instance, load model, retrive data and display it in your layout.

    Enable hooks

    $config['enable_hooks'] = TRUE;
    

    Define a hook like:

    $hook['pre_controller'] = array(
                                    'class'    => 'MyClass',
                                    'function' => 'Myfunction',
                                    'filename' => 'Myclass.php',
                                    'filepath' => 'hooks',
                                    'params'   => array('beer', 'wine', 'snacks')
                                    );
    

    E.g.

    Hook

    <?php
    
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Gamescount
    {
            private $model_name = '';
    
            public function __construct() 
            {
                    $this->CI =& get_instance();
                    $this->model_name = 'Games_model';
                    $this->CI->load->database();
                    $this->CI->load->model($this->model_name);
                    $this->CI->load->helper('url');
            }
    
            public function count_games()
            {
                    $all_games = $this->CI->Games_model->getAllGames();
                    $this->CI->gamescount = count($all_games);
            }
    }
    
    ?>
    

    In your layout you can get gamescount value like

    <?php echo $this->gamescount; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with codeigniter and the .htaccess, I have been looking for
I have been looking all over for how to compare char elements in a
I have been looking all over the Internet for an answer to this question
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking around for a visualization framework that would aid graph visualization
I have been looking online to find documentation for the function in QTP and
I have been looking into AWS spot instances for some jobs however instead of
I have been looking into backbone.js and I can't seem to figure out how
I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the
I have been looking for an answer to this on Stack Overflow, but I

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.