Book Image

CodeIgniter Web Application Blueprints

Book Image

CodeIgniter Web Application Blueprints

Overview of this book

Table of Contents (16 chapters)
CodeIgniter Web Application Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the controller


We're going to create only one controller in this project, which is /path/to/codeigniter/application/controllers/tasks.php.

Let's go over that controller now, look at the code, and discuss how it functions.

Create the /path/to/codeigniter/application/controllers/tasks.php file and add the following code to it:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Tasks extends MY_Controller {
  function __construct() {
  parent::__construct();
    $this->load->helper('string');
    $this->load->helper('text');
    $this->load->model('Tasks_model');
    $this->load->library('form_validation');
    $this->form_validation->set_error_delimiters('<div class="alert alert-danger">', '</div>');
  }

The index() function performs a couple of tasks: displaying a list of tasks and handling the form submission (validation, error checking, and so on).

Initially, we set the validation rules for the form, as follows...