Fork me on GitHub

Codeigniter Simplicity

The simplest Codeigniter Template Library you've ever saw!

Codeigniter Simplicity is a Codeigniter Template Library that is here to make our life easier.

It's been a while that there is not any official Template/Layout library inside Codeigniter. In that case I've created the Codeigniter Simplicity that is based on core functionalities of Codeigniter as it represents to me the "How it should be" project.

The code is really simple to use and the naming of the functions are pretty obvious of what they are doing without any more complexity

Obviously the first thing that you have to do is downloading the library. Make sure that you have Codeigniter at your project before using this library. They are two options to download the library:

Download latest stable version 0.7 or download latest development version from github

Once downloaded, unzip the compressed folder and copy the folder into your codeigniter Project. That's it really! You don't need any configuration to do and your previous project will be as it was before.

To help you understand how your project will be after the copying of the files and folder, it should look something like this:

│  ├──welcome.php
│  ├──index.html
│  ├──example.php
│  ├──index.html
│  ├──MY_Loader.php
│  ├──MY_Output.php
├── ...
│     ├──simple.php
│     ├──blank.php
│     ├──default.php
│     ├── ...
│  ├── ...
│        ├──general.css
│        ├──bootstrap.css
│        ├── ...
│        ├──jquery-1.9.1.min.js
│        ├──bootstrap.min.js
│        ├── ...
│        ├──glyphicons-halflings.png
│        ├──favicon.png
│        ├── ...

This is a good structure for your templates

A good way to start actually is by checking the examples that the project has inside. There is a Controller with name Example and there they are lot of examples of how to use Codeigniter Simplicity

The Controller Example will look something like this:
class Example extends CI_Controller {
    function __construct()
    public function index()
    public function example_1()
    public function example_2()
    public function example_3()
        $this->load->section('sidebar', 'ci_simplicity/sidebar');
    public function example_4()
And the template file:
<html lang="en">
        <title><?php echo $title; ?></title>
        <meta name="resource-type" content="document" />
        <meta name="robots" content="all, index, follow"/>
        <meta name="googlebot" content="all, index, follow" />
    /** -- Copy from here -- */
    foreach($meta as $name=>$content){
        echo "\n\t\t";
        ?><meta name="<?php echo $name; ?>" content="<?php echo $content; ?>" /><?php
    echo "\n";
        echo "\n\t\t";
        ?><link rel="canonical" href="<?php echo $canonical?>" /><?php
    echo "\n\t";
    foreach($css as $file){
         echo "\n\t\t";
        ?><link rel="stylesheet" href="<?php echo $file; ?>" type="text/css" /><?php
    } echo "\n\t";
    foreach($js as $file){
            echo "\n\t\t";
            ?><script src="<?php echo $file; ?>"></script><?php
    } echo "\n\t";
    /** -- to here -- */
        <!--[if lt IE 9]>
            <script src=""></script>
<?php echo $output; ?>
Code Description Example
$this->output->set_template($template) Set a template $this->output->set_template('default');
$this->output->unset_template() Unset any template that was set $this->output->unset_template();
$this->load->section($section, $ci_view [, $data ]); Load a section to the template $this->load->section('sidebar', 'ci_simplicity/sidebar');
$this->load->get_section($section); Get the section at the template $this->load->get_section('sidebar');
$this->load->js($js_files); Load js files $this->load->js('assets/js/jquery.min.js');
$this->load->css($css_files); Load css files $this->load->css('assets/css/general.css');
$this->output->set_canonical($canonical); Add canolical metatag $this->output->set_canonical(site_url('about'));
$this->output->set_meta($name,$content); Add metatag $this->output->set_meta('description','Lorem Ipsum');
$this->output->set_common_meta($title, $description, $keywords) Set common meta Data $this->output->set_common_meta('About me', 'This is a page about me', 'about, John, CV');
Note: The below example is an iframe so it might appeared with a scroll bar or in some cases it may not appear at all! If you are experiencing problems with the iframe you can also see the example at a new tab
	#5 - Fix error Array to string conversion by implode meta keywords if its value is array
	Compatibility with Codeigniter 3.x
	Load CSS files
	Load JS files
	Set Template
	Set Sections
	Set Meta Data
	Set Title
	Set Common Meta Data
	Set Canonical Meta Data
	Load CSS and JS files inside the view
	Unset Template

If you've successfully installed the template library, the very next step would be to create a CRUD for your Codeigniter application. Fortunately this is very easy as well and you can achieve a full CRUD with just few lines of code.

Grocery CRUD is a completely free library for Codeigniter and It is seriously very easy to work with. For example in order to have a full CRUD, you will just need the below lines of code:

$crud = new grocery_CRUD();
$output = $crud->render();

For more about Grocery CRUD, you can visit the page: