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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:32:26+00:00 2026-06-15T17:32:26+00:00

For my Codeigniter site, I started by making a view for each controller situation.

  • 0

For my Codeigniter site, I started by making a view for each controller situation. This was impractical, as it would require going back to the code for each to make a change. So I changed approach and operated on a ‘default’ controller with optional fields. I then thought I could load special views as needed into it.

I put together this view with optional fields with fields for $title, $search_bar on/off etc. However, now came the content area. I was able to load more views into this default view using:

        $data['content_views'][]='blocks/login';

        $this->load->view('default/a', $data);

and in the ‘default’view:

if(isset($content_views)&& (is_array($content_views)))
    {
        foreach($content_views as $content_view)
        {
            $this->load->view(&$content_view);
        }
    }

(and that works fine)
Two questions:

  1. Am I making things to complex? Is this an accepted way of doing this? Or have I misunderstood the functioning of a view and how they are intended to work?

  2. I want a way to mix the $content_view, i.e. a block of text, then a view. I’m not quite sure as to how to proceed. Say I want a message first, then a view, then more text. This method will only accept views.

Can anybody help me create this flexible approach?

  • 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-15T17:32:27+00:00Added an answer on June 15, 2026 at 5:32 pm

    Yeah I would say you’re making things a little complex. While I may not be following your description well enough to know precisely how to respond, I can tell you how I do it:

    First the whole site is run through a template so the header and footer are the container file and all views needed within the site are rendered as page type views – like an article page, a gallery page, etc. Components are loaded and passed to the views as strings:

    $content['sidebar'] = $this->load->view('components/sidebar', $data, true);
    

    That last true says to render as string.

    Essentially, this means the page views are pretty much html with php echoing out the necessary elements. No views calling other views, which is how I read your example.

    CI loads views progressively, so your controller can output like so:

    $this->load->view('header', $header_data);
    
    $view_data['sidebar'] = $this->load->view('components/sidebar', $sidebar_data, true);
    $this->load->view('content', $view_data);
    
    $this->load->view('footer', $footer_data);
    

    and in content view, handle the sidebar like so:

    <?php if(isset($sidebar)): ?>
    <nav>
        <?php echo $sidebar; ?>
    </nav>
    <?php endif; ?>
    

    And, assuming you populate those arrays for each view it will render header, then content, then footer. And also render sidebar if it is present.

    So combining everything, I’m basically saying you can load in sections in your controllers progressively, passing sub-views as strings to whichever section makes sense. That keeps your view controlling in the controller where it belongs and not in the view files themselves. In my experience, I have not had to write a site that was so complex that this construct wasn’t perfectly suitable if the site is planned well.

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

Sidebar

Related Questions

Ive started a codeigniter site. my default controller is $route['default_controller'] = login; in routes.php
I am making a site for a client and decided i would use code
I'm in the process of building a site with CodeIgniter. This is the 1st
I am planning a new website with codeigniter using wordpress. this site will contain
I just started using CodeIgniter after using Zend for a while. My new site
I've been rebuilding my site using CodeIgniter. I am currently making the sign up
I am developing a site with codeigniter and would like to know which caching
I am recoding my site using CodeIgniter. This is my first time using an
I would like to integrate gapi in my codeigniter site. So I have been
Basically, I have a CodeIgniter site that registers users through this url: http://website.com/user/register/1 Unfortunately,

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.