Free CodeIgniter Tutorial


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.

http://localhost/codeigniter/index.php/

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)

VIEW

 

<?php

$this->load->helper(‘form’);

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)

Model     

<?php

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)

Controller

<?php

class Register_form extends CI_Controller{

function Register_form()

{     parent::__construct();

}

function forms(){

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

}

function createlogin() {

$this->load->library(‘form_validation’);

$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

echo”fail”;

}

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

http://localhost/CodeIgniter/index.php/Register_form/forms

View Database Details Using Codeigniter

View

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

$this->load->helper(‘form’);

echo form_open(‘View_database_details/view_databse’);

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

?>

Model

<?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()

{

$query=$this->db->get(‘login’);

return $query->result();

} //viewdatabse

}//class

?>//php

 

Controller

<?php

class View_database_details extends CI_Controller

{

function viewform()

{

$this->load->view(‘view_details’);

}

Load viewdatabase function In Model

function view_databse(){

$this->load->model(‘View_database_model’);

$data[‘query’]=$this->View_database_model->viewdatabases();

<?

foreach($query as $row) {

“;echo” $row->name;

echo” $row->password”;

print “<br>”;

}

?>

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

result.php

Save in view folder

}

}

This will Display this Database Results

?>

 

 

 

http://localhost/CodeIgniter/index.php/View_database_details/viewform

Upload_form.php  Save in View folder

Upload  and Display Image Using Codeigniter

View

<?php

$this->load->helper(‘form’);

echo form_open_multipart(‘image_upload/uploadfile’);

echo form_upload(‘file’);

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

Image_upload.php

Save in Controller

?>

Controller

<?php

class Image_upload extends CI_controller

{

function image_upload()

{

parent::__construct();

}

function image()

{

$this->load->view(‘upload_form’);

}

function uploadfile() {

$config[‘upload_path’]=’uploads/’;

$config[‘allowed_types’]=’gif|jpg|png|jpeg’;

$config[‘max_size’]=’1000′;

$config[‘max_width’]=’1920′;

$confing[‘max_height’]=’1280′;

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

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

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

$this->_createThumbnail($fInfo[‘file_name’]);

$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

view

<body>

<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>

</dl>

<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

file

This Controller Class  name

http://localhost/CodeIgniter/index.php/image_upload/image

 

 

 

 

M   .  V  .  C

 

Advertisements

3 thoughts on “Free CodeIgniter Tutorial

    • The Model is the name given to the permanent storage of the data used in the overall design. It must allow access for the data to be viewed, or collected and written to, and is the bridge between the View component and the Controller component in the overall pattern

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s