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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:45+00:00 2026-05-22T14:23:45+00:00

Hey guys, I am new to CodeIgniter and need some help. I have a

  • 0

Hey guys, I am new to CodeIgniter and need some help. I have a controller that formats the content area of a post. The problem is that I also need to create a sidebar that contains dynamic groups, and a right column that contains recent posts. This isn’t hard, the problem I’m running into is that I want the sidebar, and right column on every page, and I don’t want to recode the same bits to get the data in every controller.

What would be the best way to do this without copy/paste?

  • 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-22T14:23:45+00:00Added an answer on May 22, 2026 at 2:23 pm

    There are a lot of ways to do this.

    1) Templating: This is my preference for most cases (because my templates are complex), I render my view into a variable using something like:

    $content = $this->load->view('myview', $page_data, true);
    

    Then I load it into the template parser (fyi you could load it into another view too) like this:

    $this->load->library('parser');
    $data = array(
            'page_title' => 'My Page Title',
            'page_content' => $content,
            'side_bar' => side_bar(), // function which generates your side bar
            'right_col' => right_col() // function which generates your right column
            );
    $this->parser->parse('my_template', $data);
    

    Then your template is like:

    <html>
    <head>
    <title>{page_title}</title>
    </head>
    <body>
        <div>{side_bar}</div>
        <div>{page_content}</div>
        <div>{right_col}</div>
    </body>
    </html>
    

    2) Load another view in your view: (assumes you menu is a view not a controller) Something like this:

    <?php $this->load->view('menu_view'); ?> 
    

    3) PHP Includes: exactly how you would do it in plain PHP (just include a url which points to a controller which returns a menu), Something like this:

    <?php include("/common/sidebar"); ?>
    

    Codeigniter will render that page and then include it.

    4) AJAX.. i use this if the content in the “template” content is less important, like banners, suggested related item lists and such.

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

Sidebar

Related Questions

Hey guys! I'm new to C, so i would like help in one problem.
Hey guys I'm new to JS and I'm trying to combine some functions I
Hey guys I have a simple create method with some validations and whenever the
Hey guys, I have a problem (again). This time I am trying to use
Hey guys. I have a method that gets called each second which I want
Hey guys, I'm new to mysqli and I have a question. I just updated
Hey guys.I'm new to android and with the help of stackoverflow I somehow managed
Hey guys I am pretty new to JQuery and I have a question about
Hey guys i have the string: /new/krymson/ currently i have the regex: /\/new\// which
Hey guys, sorry I am new to Jquery. I have always tried to do

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.