Code Igniter

Installation and First Run:

1. Download the zip file from the above URL.  Unzip  and put in to xampp/htdoc folder

2. Open the application/config/config.php file with a text editor and set your base URL. lets asumme that your base URL is set like this:

$config[‘base_url’] = http://localhost/CodeIgniter;

3. if you intend to use a database, open the application/config/database.php file with a text editor and set your database settings. Set the following variables according to your setup.

$db[‘default’][‘hostname’] = “localhost”;
$db[‘default’][‘username’] = “admin”;
$db[‘default’][‘password’] = “*****”;
$db[‘default’][‘database’] = “projectone”;
$db[‘default’][‘dbdriver’] = “mysql”;
$db[‘default’][‘dbprefix’] = “”;
$db[‘default’][‘active_r’] = TRUE;
$db[‘default’][‘pconnect’] = TRUE;
$db[‘default’][‘db_debug’] = TRUE;
$db[‘default’][‘cache_on’] = FALSE;
$db[‘default’][‘cachedir’] = “”;

5. now you are ready to run our installed piece of software. in order to run Code Igniter you have to visit the following URL in you web server.


if your setup is correct then you will see a welcome page with heading

“Welcome to Code Igniter!”

 Format of run the Codeigniter project :

 Ex:  http://localhost/foldername(Projectfolder)/index.php/Controllerclass name/function name in controller Class

Insert data Into Database Using Codeigniter

Form.php   (Save as   view   folder)





echo form_open(‘Register_form/createlogin’); //Doing Action

echo form_input(‘username’,’venu’); echo”<br>”;

echo form_input(‘password’,’password’);                                                        Creating Text box s and                  

echo form_submit(‘submit’,’create account’);                                                            Submit  Button


Insert_model.php (Save as   Model   folder)



class Insert_model extends CI_Model{

function Insert_model()

{           parent::__construct();


function insertdata()

{                                                                                          Database Column Names

$new_member_insert_data =

array(‘name’ => $this->input->post(‘username’),’password‘=>$this->input->post(‘password’));

$this->db->insert(‘login’,$new_member_insert_data);                                    Text Box Names

return ;

}                                      Table Name

}      ?>

Register.php (Save as   Controller folder)



class Register_form extends CI_Controller{

function Register_form()

{     parent::__construct();


function forms(){

$this->load->view(‘form’);                                      Calling  Index form


function createlogin() {


$this->form_validation->set_rules(‘username’, ‘Name’,’trim|required’);

$this->form_validation->set_rules(‘password’, ‘password’,’trim|required’);        Form Validation

if($this->form_validation->run() == FALSE)

{ $this->load->view(‘form’);


$this->load->model(‘Insert_model’);                         Calling Model file

if($query=$this->Insert_model->insertdata())                     Load the  ‘insertdata’ function                 

            {                                                                                                                    in Model



else{    echo”succes”;  }           }//createlogin   }//Class    ?>//close php


View Database Details Using Codeigniter


<?php                                                                                      View _details.php (Save in View folder)


echo form_open(‘View_database_details/view_databse’);

echo form_submit(‘submit’,’view’);



<?php                                                                                         View_database_model(save in Model )

class View_database_model extends CI_Controller{

function View_database_model()

{     parent::__construct();

Here get means “select *form tablename


function viewdatabases()



return $query->result();

} //viewdatabse






class View_database_details extends CI_Controller


function viewform()




Load viewdatabase function In Model

function view_databse(){




foreach($query as $row) {

“;echo” $row->name;

echo” $row->password”;

print “<br>”;





Save in view folder



This will Display this Database Results






Upload_form.php  Save in View folder

Upload  and Display Image Using Codeigniter




echo form_open_multipart(‘image_upload/uploadfile’);

echo form_upload(‘file’);

echo form_submit(‘submit’,’Upload’);


Save in Controller




class Image_upload extends CI_controller


function image_upload()




function image()




function uploadfile() {







if(!$this->upload->do_upload(‘file’))            echo $this->upload->display_errors();

else {   $fInfo = $this->upload->data();


$data[‘uploadInfo’] = $fInfo;

$data[‘thumbnail_name’] = $fInfo[‘raw_name’] . ‘_thumb’ . $fInfo[‘file_ext’];

$this->load->view(‘upload_success’, $data);

}                    }

function _createThumbnail($fileName) {

$config[‘image_library’] = ‘gd2’;

$config[‘source_image’] = ‘uploads/’ . $fileName;

$config[‘create_thumb’] = TRUE;

$config[‘maintain_ratio’] = TRUE;

$config[‘width’] = 575;

$config[‘height’] = 75;

$this->load->library(‘image_lib’, $config);

if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();




Upload_success .php

Save in View floder



<div id=”container”>

<p>Congratulations. Your photo has been uploaded successfully. </p>

<dl>     <dt>File Name: </dt>

<dd> <?= $uploadInfo[‘file_name’]; ?> </dd>

<dt>File Size: </dt>

<dd> <?= $uploadInfo[‘file_size’]; ?> </dd>

<dt> File Extension: </dt>

<dd> <?= $uploadInfo[‘file_ext’]; ?> </dd>


<img alt=”Your Image” src=”<?= base_url() . ‘uploads/’ . $file_Name;?>” />

<img alt=”Your Thumbnail” src=”<?= base_url() . ‘uploads/’ . $thumbnail_name;?>” />

</div>    </body>

This Function name in Controller


This Controller Class  name






M   .  V  .  C