Welcome Guest, Not a member yet? Register   Sign In
Practical CodeIgniter 3 - A new book coming soon

The simplest solution is to put the code in that chapter into your MY_Controller file. The My_Controller example file that you should have received with the book has the functions already in there. Then, all of your controllers would extend from that. At this point, all of the functions are available to your controllers. Then, the $this->render() method would display the current view based on your controller and message name. We'll walk through a quick example assuming a user profile page.

First, create your main "layout" file. This is the template that is used for all of the pages that your content gets inserted into. Make sure the echo out a view_content variable.

<!doctype html>
    <title>Some Great Site</title>
    <link rel="stylesheet" href="/assets/css/app.css">
    <!-- Header stuff goes here -->

    <div class="container">
        <?= $view_content ?>

    <!-- Footer stuff goes here -->

Then, in your controller, you might do something as simple as:

class Users extends MY_Controller {
    public function index() {
        $data = [
            'user' => $this->auth->current_user();


This will look for a view file at application/views/users/index.php. You would fill that view file with any content that you needed to, and it would be inserted into the layout file at the place where the $view_content is output.

There's more details to it, of course, but is that enough for it all to make sense? Sounds like I need to clarify that part of the book a little more with an example or two.

Messages In This Thread
RE: Practical CodeIgniter 3 - A new book coming soon - by kilishan - 02-15-2016, 08:43 AM

Theme © iAndrew 2016 - Forum software by © MyBB