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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:09:25+00:00 2026-05-28T20:09:25+00:00

I’m working with a controller name page.php . This is what I have: class

  • 0

I’m working with a controller name page.php. This is what I have:

class Page extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    public function index() {
        show_404();
    }

    public function view($id) {
        $query = $this->db->query("
            SELECT * FROM proposals
            WHERE id='$id'");

        if ($query->num_rows() == 1) {
            $row = $query->row();
            $data['proposal_id']          = $id;
            $data['proposal_title']       = $row->title;
            $data['proposal_proposer']    = $row->proposer;
            $data['proposal_summary']     = $row->summary;
            $data['proposal_description'] = $row->description;
            $data['proposal_date']        = $row->date;
            $data['proposal_vote']        = $row->vote;
            $data['proposal_source']      = $row->source;
            $query->free_result();   
        } else {
            show_404();
        }

        // Get user data
        $user_info['logged_in'] = "";
        $user_info['username']  = "";
        $user_info['user_id']   = "";
        $user_info['score']     = "";

        // Get special variables needed for the header
        $header_data['page_title']       = htmlspecialchars($data['proposal_title']);
        $header_data['page_description'] = htmlspecialchars($data['proposal_summary']);

        // Get special variables needed for the footer
        $footer_data['stats_proposals'] = "12";
        $footer_data['stats_users']     = "42";

        // Check if this is an edit


        // Load the views (interfaces) in order
        $this->load->view('templates/header', $header_data);
        $this->load->view('page',             $data);
        $this->load->view('templates/footer', $footer_data);
    }
}

As shown above, I am manually calling the header using $this->load->view('templates/header', $header_data); and passing some info to it. However, in my case, this info will always be the same across the site. There a way for me to call some sort of controller BEFORE loading the view for the header?

  • 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-28T20:09:26+00:00Added an answer on May 28, 2026 at 8:09 pm

    You could create a library & model to complete all your DB queries. This would also clean up the $query = $this->db->query() bit so that it would be in your model rather than your controller.

    Then, each time you need to load the header view, you could use this in your controller:

    $header_data = $this->library_name->function_to_get_header_info($id);
    $this->load->view('templates/header', $header_data);
    

    The actual library would accept the variables needed to create this header view (for example, $id). It would make a call to the model, which would perform any actual DB queries (for example, $query = $this->db->query("SELECT * FROM proposals WHERE id='$id'");). Then the library would make the data returned by the model usable by the view (for example, setting page_title & page_description to $row->title & $row->summary, respectively).

    • 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’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.