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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:54:19+00:00 2026-05-12T05:54:19+00:00

What is the best way to use controllers/views in CodeIgniter ? Is the following

  • 0

What is the best way to use controllers/views in CodeIgniter?

Is the following a bad way to go about making my pages?

function index()
{
    $this->load->library('carabiner');      
    $this->load->view('include/head');
    $this->load->view('include/home');
    $this->load->view('top');
    $this->load->view('featured');
    $this->load->view('eventslist');
    $this->load->view('footer');    
}

function create()
{
    $this->load->view('include/head');
    $this->load->view('top');
    $this->load->view('page');
    $this->load->view('dynamicstuff');
    $this->load->view('footer');
}

I’m quasi-templating this way, and it works fine for getting the outline of the site, but is it the best way to create an app?
I’ve been working in CodeIgniter for about a week now, and I’m new to PHP.

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

    There is a download called CodeIgniter Library that makes all this very easy. Once you learn how to implement it, coding becomes very easy. It also allows you to change each page or controller to have different templates (layouts).

    Using the system I mentioned above you can do the following:

    <?php
    
        function index() {
    
            $data['some_variable'] = 'some data';
    
            $this->template->write_view('content', 'page/home', $data);
            $this->template->render();
    
        }
    
    ?>
    

    Anywhere you can also change which template you wish to use:

    <?php
    
        $this->template->set_template('login');
    
    ?>
    

    All these templates have names that are kept in a configuration file. You can have as many templates as you wish.

    The template file itself would look something like this:

    <html>
    .... etc. all other html elements
        <body>
            header html goes here
    
            <?=$content?>
    
            footer html goes here
        </body>
    </html>
    

    You can even set up sections to be able to write your content to. I don’t usually do this because it is including a lot of views, but if you need full control like this you are still able to do so:

    <?php
    
        function index() {
    
            $data['header'] = 'header info';
            $data['content'] = 'content info';
            $data['sidebar'] = 'sidebar info';
            $data['footer'] = 'footer info';
    
            $this->template->write_view('content', 'page/home', $data);
            $this->template->write_view('header', 'modules/header');
            $this->template->write_view('sidebar', 'modules/sidebar');
            $this->template->write_view('footer', 'modules/footer');
    
            $this->template->render();
    
        }
    
    ?>
    

    HTML template code:

    <html>
    .... etc. all other html elements
        <body>
            <div id="header">
                <?=$header?>
            </div>
    
            <div id="content">
                <div id="left">
                    <?=$content?>
                </div>
    
                <div id="sidebar">
                    <?=$sidebar?>
                </div>
            </div>
    
            <div id="footer">
                <?=$footer?>
            </div>
        </body>
    </html>
    

    This way you only have to worry about including one file in all your Controller Functions. If you are not using PHP 5 (you should switch) then instead of using <?=$content?> you will want to use <?php echo $content; ?>.

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

Sidebar

Related Questions

I'm wondering what the best way is to use the XDocument.load and save methods
What is the best way to use an embedded database, say sqlite in Python:
what is best way to use logger in JSF application
I'm curious as to the best way to use the relatively new pushState feature
I was wondering what the best way to use transations with the entity framework.
I'm looking for the best way to use a duration field in a Rails
I'm trying to find the best way to use Java libraries that were installed
I am investigating since a few hours the best way to use the Email
I'm just wondering if what is the best way to use BitmapFactory ? I'm
I can't figure out what would be the best way to use Bucket Sort

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.