Showing posts with label Codeigniter. Show all posts
Showing posts with label Codeigniter. Show all posts

Codeigniter Frameworks

Codeigniter Frameworks

Codeigniter Frameworks is a powerful PHP Frameworks with a very small footprint, built for developer and very easily learn in Codeigniter Frameworks. Basic Introduction of Codeigniter Framework  Please Click Here   

Codeigniter Frameworks
Codeigniter Frameworks


Best Features of Codegniter

  • Model-View-Controller System(MVC)
  • Light Wight
  • Full Featured database classes with support for several platforms
  • Form and Data Validation
  • Active Record Databasupport
  • FTP Class
  • Session Management
  • Security and XSS Filtering
  • Email Sending Class. Support Attachments, HTML/Text email, and Multiple Protocols
  • Localization
  • Pagination and Image manipulation LibraryC
  • Search Engine Friendly URL's
Codeigniter Session Storage

Codeigniter Session Storage is very simpley and easily storage Login Authentication Username storage session Read More

Important Codeigniter Tutorial


Security Features of Codeigniter Frameworks 

1.Codeigniter Seacurity Features First Remote code Execution <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> This Ensures that the PHP Files is not accessible directly by manipulating or running a script, which would compromise the system.

2.SQL injection: This type of attack is highly common on the web. A SQL injection occurs when an attacker exploits the front-end and the post data to retrieve secure data from the database. According to CodeIgniter manual, it becomes evident that your web application is automatically safe from SQL injection as the POST data is retrieved in the controller using $this->input->post (‘’); which is automatically filtered by CodeIgniter.  CodeIgniter User Manual excerpt proves this fact: “Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.”

3,XSS Attacks: An XSS or Cross Site scripting attack is unarguably the common reason for the demise of web applications. A XSS attack works by a hacker crafting a malicious URL into the browser in order to compromise the security of the application. CodeIgniter has a built in XSS filter which is initialized automatically. In order to double check the security threats against XSS attacks, a Firefox add-on called XXS Me (download here) can be used to test the sample application against 96 different types of attacks. The results are shown in the image below. It shows that the all form input fields were not found unencoded, which means the XSS filter within CodeIgniter did its job.

Codeigniter full featrued JQuery datatables

Codeigniter full featrued JQuery datatables


PHP Codeigniter full featrued Jquery datatables means fetch data display table default set pagination and filter included more featreued in datatable. Create cool full featured datatables for your daily in any Codeigniter  Projects specially CMS and how to add controls.

Codeigniter full featrued JQuery datatables
Codeigniter full featrued JQuery datatables

You are Familiar with Codeigniter
You have a webserver up and running (XAMP,LAMP, AND WAMP Server)

example database code:

CREATE TABLE `demotable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first` varchar(100) DEFAULT NULL,
`last` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;
insert into `demotable`(`id`,`first`,`last`,`email`,`date_created`) values (23,'Amedd','samy','dev2tricks@gmail.com','2013-03-11 23:11:40');
insert into `demotable`(`id`,`first`,`last`,`email`,`date_created`) values (24,'John','Carter','test@test.com','2013-03-11 23:19:05');
insert into `subscriber`(`id`,`first`,`last`,`email`,`date_created`) values (25,'Lina','Khaled','lina@hotmail.com','2013-03-17 20:54:48');
Download and extract Codeigniter in your root folder

Change base_url  in your application/config/config.php file to

$config['base_url'] = 'http://localhost/tutorial_datatables;

Make sure you set database configuration in your application/config/database.php

-Download ignited datatables library from https://github.com/IgnitedDatatables/Ignited-Datatables

-Copy Datatables.php in application/libraries

-Download Datatables JS plugin from http://www.datatables.net/download/

- Create assets folder with the below structure

Copy jquery.dataTables.min.js   from  DataTables-1.9.4\media\js  to assets\js

-Create a CSS file called style.css in assets/css

body{font-family:Arial,Helvetica,sans-serif;background-color:#F0F0F0;font-size:12px;}
h1{color:#072936;}
.wrapper{width:730px;margin:0 auto;}
footer{border-top:1px solid #CCC;float:right;font-size:12px;width:81%;margin:40px 0 0;padding:10px;}
#big_table_wrapper{background-color:#fff;}
#big_table_wrapper .dataTables_length{float:left;}
#big_table_wrapper .dataTables_filter{float:right;}
#big_Table_wrapper .ui-toolbar{padding:5px;}
#big_table{width:730px;text-align: center;}
.dataTables_paginate .ui-button{margin-right:-.1em!important;}
.paging_full_numbers .ui-button{color:#333!important;cursor:pointer;margin:0;padding:2px 6px;}
.dataTables_info{float:left;width:50%;padding-top:3px;}
.dataTables_paginate{float:right;text-align:right;width:auto;}
.paging_full_numbers{width:350px!important;}
#big_table_processing > img{padding-left:20px;}</code>

-Change the default controller in application/config/routes.php

$route['default_controller'] = "subscriber";

Application/Controller
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Subscriber extends CI_Controller
{
 
    public function __construct()
    {
        parent::__construct();
        $this->load->library('Datatables');
        $this->load->library('table');
        $this->load->database();
    }
 
    function index()
    {
 
        //set table id in table open tag
        $tmpl = array('table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="mytable">');
        $this->table->set_template($tmpl);
 
        $this->table->set_heading('First Name', 'Last Name', 'Email');
 
        $this->load->view('subscriber_view');
    }
 
    //function to handle callbacks
    function datatable()
    {
        $this->datatables->select('id,first,last,email')
            ->unset_column('id')
            ->from('subscriber');
 
        echo $this->datatables->generate();
    }
}

Application/View
<h1>Subscriber management</h1>
<?php echo $this->table->generate(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var oTable = $('#big_table').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": '<?php echo base_url(); ?>index.php/subscriber/datatable',
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "iDisplayStart ": 20,
            "oLanguage": {
                "sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
            },
            "fnInitComplete": function () {
                //oTable.fnAdjustColumnSizing();
            },
            'fnServerData': function (sSource, aoData, fnCallback) {
                $.ajax
                ({
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': fnCallback
                });
            }
        });
    });
</script>
$('#big_table').dataTable
"sAjaxSource":'<?php echo base_url(); ?>index.php/subscriber/datatable'
<?php echo $this->table->generate(); ?>



Prevent SQL injection in Codeigniter (CI)

Prevent SQL injection in Codeigniter (CI)


SQL injection is an attack made on database query.  In PHP, we are use mysql_real_escape_string()
function to prevent this along with other techniques but codeigniter provides inbuilt function and libraries to prevent this.Join Queries

Prevent SQL injection in Codeigniter (CI)
Prevent SQL injection in Codeigniter (CI)


We can prevent SQL Injection in CodeIgniter in the following three ways  

Escaping Queries
Query Biding
Active Record Class



Escaping Queries
<?php
$name = $this->input->post('uname');
$cn = 'SELECT * FROM tbl_users WHERE user_name='.$this->db->escape($name);
$this->db->query($cn);
?> 
Here $this->db->escape() determines the data type so that it can escape only string data.
It also automatically adds single quotes around the data so you don’t have to do that as well.

Preventing SQL injection in Codeigniter using Query Binding Method 

<?php
    $sql = "SELECT * FROM subscribers_tbl WHERE status = ? AND email= ?";
    $this->db->query($sql, array('active', 'dev2tricks.com.in'));
?>
The query are automatically replaced with the values in the array in the second parameter of the query function.

in Query Binding Method, you don’t have to escape the values manually as it will automatically do that for you.


Preventing SQL injection in Codeigniter using Active Record Class

<?php
   $this->db->get_where('subscribers_tbl',array('status' => 'active','email' => 'dev2tricks.com.in'));
?>

Codeigniter PDF File Upload

Codeigniter PDF File Upload


PDF File Upload Codeigniter Framework mostly discussed previously and this post is about uploading files in Codeigniter has upload library by using this class we can upload file on server very easily. Codeigniter session Storage

Codeigniter PDF File Upload
Codeigniter PDF File Upload


<?php
echo $error;
echo form_open_multipart('upload/do_upload');
echo form_input(array('type' => 'file','name' => 'userfile'));
echo form_submit('submit','upload');
echo form_close();
?>

Controller method you need to set some config setting like uploading path, allowed types, upload sizes, width height,... etc.

    function upload(){
        $this->load->library('upload');   
        $config['upload_path'] = './assets/certificates/';
        $config['allowed_types'] = 'pdf';
        $config['max_size']    = '1000000';
        $config['file_name'] = "upload";

        $this->upload->initialize($config);
        $certificateflag = $this->upload->do_upload("certificate");       
        if ($this->upload->do_upload("certificate"))
            error_reporting(E_ALL);
        else{
            echo "<pre>"; Print_r($this->upload->data()); echo "</pre>";
        }
}<?php

Library Codeigniter PDF File upload root directory Follows


Open <root_directory>/system/application/config/mimes.php file

Change value of ‘pdf’ element of $mimes array

$mimes = array( ‘hqx’   =>      ‘application/mac-binhex40’,
‘cpt’   =>      ‘application/mac-compactpro’,
‘csv’   =>      array(‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/vnd.ms-excel’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’),
‘bin’   =>      ‘application/macbinary’,
‘dms’   =>      ‘application/octet-stream’,
‘lha’   =>      ‘application/octet-stream’,
‘lzh’   =>      ‘application/octet-stream’,
‘exe’   =>      ‘application/octet-stream’,
‘class’ =>      ‘application/octet-stream’,
‘psd’   =>      ‘application/x-photoshop’,
‘so’    =>      ‘application/octet-stream’,
‘sea’   =>      ‘application/octet-stream’,
‘dll’   =>      ‘application/octet-stream’,
‘oda’   =>      ‘application/oda’,
‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’),

To

‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’, ‘application/x-download’,’application/x-download’, ‘binary/octet-stream’, ‘application/unknown’, ‘application/force-download’),

Codeigniter Ajax Pagination


Codeigniter Ajax Pagination

Codeigniter Ajax Pagination today solve this task so just share with your. Today we will discuss how to create ajax pagination in Codeigniter Framework. Codeigniter have the pagination library by default.  But many times we are needed to implemented ajax based pagination in codeigniter. and pagination responsive design you implemented your own designed.

Already we discussed codeigniter framework and other related topics so just go the task at first we need to add ajax pagination into the Codeigniter Pagination library.  Copy the Codeigniter pagination library and modify with ajax pagination code.  Rename the Pagination Class to Ajaxpagination and insert the Ajaxpagination.php file into the library folder.  you can download the CodeIgniter Ajax pagination library from the Click Here

   
Codeigniter Ajax Pagination
Codeigniter Ajax Pagination
First Create table


CREATE TABLE `dent_adminusers` (
  `id` int(11) NOT NULL auto_increment,
  `adminname` varchar(50) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `status` enum('Active','Suspend','Deactive') NOT NULL default 'Deactive',
  `mailstatus` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

Controller

Create a controller file named posts.php with Posts classed. Into the __construct() function we need to load post model.  Ajaxpagination library. And we set the per page data limit into the $this-perPage variable.


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Posts Management class created by CodexWorld
 */
class Posts extends CI_Controller {
    
    function __construct() {
        parent::__construct();
        $this->load->model('post');
        $this->load->library('Ajaxpagination');
        $this->perPage = 1;
    }
    
    public function index()
    {
        $data = array();
        
        //total rows count
        $totalRec = count($this->post->getRows());
        
        //pagination configuration
        $config['first_link']  = 'First';
        $config['div']         = 'postList'; //parent div tag id
        $config['base_url']    = base_url().'posts/ajaxPaginationData';
        $config['total_rows']  = $totalRec;
        $config['per_page']    = $this->perPage;
        
        $this->ajax_pagination->initialize($config);
        
        //get the posts data
        $data['posts'] = $this->post->getRows(array('limit'=>$this->perPage));
        
        //load the view
        $this->load->view('posts/index', $data);
    }
    
    function ajaxPaginationData()
    {
        $page = $this->input->post('page');
        if(!$page){
            $offset = 0;
        }else{
            $offset = $page;
        }
        
        //total rows count
        $totalRec = count($this->post->getRows());
        
        //pagination configuration
        $config['first_link']  = 'First';
        $config['div']         = 'postList'; //parent div tag id
        $config['base_url']    = base_url().'posts/ajaxPaginationData';
        $config['total_rows']  = $totalRec;
        $config['per_page']    = $this->perPage;
        
        $this->ajax_pagination->initialize($config);
        
        //get the posts data
        $data['posts'] = $this->post->getRows(array('start'=>$offset,'limit'=>$this->perPage));
        
        //load the view
        $this->load->view('posts/ajax-pagination-data', $data, false);
    }
}


Model:

Codeigniter Ajax Pagination Create a Model file follows Code.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Post extends CI_Model{
    
    function __construct() {
        $this->postTable = 'posts';
    }
    
    function getRows($params = array())
    {
        $this->db->select('*');
        $this->db->from($this->postTable);
        $this->db->order_by('created','desc');
        
        if(array_key_exists("start",$params) && array_key_exists("limit",$params)){
            $this->db->limit($params['limit'],$params['start']);
        }elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)){
            $this->db->limit($params['limit']);
        }
        
        $query = $this->db->get();
        
        return ($query->num_rows() > 0)?$query->result_array():FALSE;
    }
}
?>


View

Codeigniter Ajax Pagination responsive or your design modify view page.


<h1>Posts</h1>
<div id="container">
    <ul class="list" id="postList">
        <?php if(!empty($posts)): foreach($posts as $post): ?>
        <li>
            <p><b>Title:</b>&nbsp;<?php echo $post['title']?></p>
            <p><b>Content:</b>&nbsp;<?php echo $post['content']?></p>
            <p><b>Created:</b>&nbsp;<?php echo $post['created']?></p>
        </li>
        <?php endforeach; else: ?>
        <li class="err_msg">Post(s) not available.</li>
        <?php endif; ?>
        <?php echo $this->ajax_pagination->create_links(); ?>
    </ul>
</div>

How to send email with CodeIgniter

How to send email with CodeIgniter


How to send email with CodeIgniter
How to send email with CodeIgniter
Today I have solve this task share with you codeigniter Mail Function Send a Mail I am  First time Implementing MVC Structure.  Following Code. Session Storage



View.html

<form action="<?php echo base_url('index.php/email/mysend_mail'); ?>" method="post">
Please, enter e-mail: <input type="text" name="e-mail"><input type="submit" name="submit" value="Submit">
</form>

Controller

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

class Email extends CI_Controller {

  public function __construct(){
    parent::__construct();
    $this->load->helper('url');
  }

public function index()
{

$this->load->view('header');
    $this->load->view('email_form');
    $this->load->view('footer');
}
  
  public function mysend_mail(){
    $this->load->helper('url');

    if (!isset($_POST['e-mail'])){
      //redirect if no parameter e-mail
      redirect(base_url());
    };

    //load email helper
    $this->load->helper('email');
    //load email library
    $this->load->library('email');
    
    //read parameters from $_POST using input class
    $email = $this->input->post('e-mail',true);    
  
    // check is email addrress valid or no
    if (valid_email($email)){  
      // compose email
      $this->email->from($email , 'xxxxx');
      $this->email->to($email); 
      $this->email->subject('My First CodeIgniter Email Example');
      $this->email->message('CodeIgniter Email Example App!');  
      
      // try send mail ant if not able print debug
      if ( ! $this->email->send())
      {
        $data['message'] ="Email not sent \n".$this->email->print_debugger();      
        $this->load->view('header');
        $this->load->view('message',$data);
        $this->load->view('footer');

      }
         // successfull message
        $data['message'] ="Email was successfully sent to $email";
      
        $this->load->view('header');
        $this->load->view('message',$data);
        $this->load->view('footer');
    } else {

      $data['message'] ="Email address ($email) is not correct. Please <a href=".base_url().">try again</a>";
      
      $this->load->view('header');
      $this->load->view('message',$data);
      $this->load->view('footer');
    }

  }
  
  public function info(){
    phpinfo();
  }
    
}

Codeigniter Session Storage

Codeigniter Session Storage


Codeigniter Session Storage
Codeigniter Session Storage
Codeigniter Session Storage is Very simpley and easly storage Login authentication  Username stored session. Codeigniter Login form
using this code:

$this->session->set_userdata() 

I just found that setting sess_encrypt_cookie to FALSE fixed the chrome logout issue.

Session Storage Config settings following Code.

$config['sess_encrypt_cookie'] = FALSE

$config['sess_match_useragent'] = FALSE;

$config['sess_expiration'] = 8600;


$this->session->set_userdata('user_session', $user_session_data);

$autoload['libraries'] = array("session");

$this->load->library('session');

Model

 function Login($email,$pass){
         $this->db->where('username' ,$email);
         $this->db->where('password',$pass);
         $query=$this->db->get('users');  
     if ($query->num_rows == 1) {        
    return true;  
     }    
     return FALSE;
    }

Controller:

   function varification(){
            $this->load->model('login_model');
    $email=$this->input->post('email');
    $pass=$this->input->post('pass');
    $success=$this->login_model->Login($email,$pass);
    if ($success) {
                 $data = array(
                       'user_name' => $rows->username,
                       'logged_in' => TRUE,
                      'validated' => true
                 );
                $this->session->set_userdata($data);
                redirect ('site/index');
    } else{ // incorrect id or password
             redirect ('site/login');
            }
    }

Simple Login with CodeIgniter in PHP

Simple Login with CodeIgniter in PHP

Simple Login with CodeIgniter
Simple Login with CodeIgniter 

CodeIgniter is an open source web application MVC structure Framework built in PHP designed to make your life as a programmer easier.  CodeIgniter allowing good speed and good performance when the site up and running. CodeIgniter details already previous post discussed CodeIgniter.

CodeIgniter Login  Database



CREATE TABLE `users` (
 `id` tinyint(4) NOT NULL AUTO_INCREMENT,
 `username` varchar(10) NOT NULL,
 `password` varchar(100) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



insert into users (username, password) values ('dev2tricks', MD5('secret'));
                                                                 or
insert into users (username, password) values ('dev2tricks', base64('secret'));

Configure CodeIgniter

Database Access

Update the file application/config/database.php in your CodeIgniter installation with your database info:


$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'yourdbusername';
$db['default']['password'] = 'yourdbpassword';
$db['default']['database'] = 'yourdbname';


Default Controller

We need to tell CodeIgniter to land into our login page instead of the default welcome page.  Update the file application/config/routes.php in your CodeIgniter installation with you controller’s name.  We’ll call our landing controller login.

$route['default_controller'] = "login";

Libraries

In the file application/config/autoload.php you can configure the default libraries you want to load in all your controllers.

$autoload['libraries'] = array('database','session');
$autoload['helper'] = array('url');


 Model (application/models/user.php)

<?php

Class User extends CI_Model
{
 function login($username, $password)
 {
   $this -> db -> select('id, username, password');
   $this -> db -> from('users');
   $this -> db -> where('username', $username);
   $this -> db -> where('password', MD5($password));
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }
}
?>



 Login Controller (application/controllers/login.php)



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

class Login extends CI_Controller {

 function __construct()
 {
   parent::__construct();
 }

 function index()
 {
   $this->load->helper(array('form'));
   $this->load->view('login');
 }

}

?>


Login View (application/views/login.php)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title>Simple Login with CodeIgniter</title>
 </head>
 <body>
   <h1>Simple Login with CodeIgniter</h1>
   <?php echo validation_errors(); ?>
   <?php echo form_open('verifylogin'); ?>
     <label for="username">Username:</label>
     <input type="text" size="20" id="username" name="username"/>
     <br/>
     <label for="password">Password:</label>
     <input type="password" size="20" id="passowrd" name="password"/>
     <br/>
     <input type="submit" value="Login"/>
   </form>
 </body>
</html>


Login Controller (application/controllers/login.php)



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

class VerifyLogin extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('user','',TRUE);
 }

 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', 'refresh');
   }

 }

 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this->input->post('username');

   //query the database
   $result = $this->user->login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}
?>

and Codeigniter database Table access insert,update delete click here


Codeigniter Insert Update Delete

PHP Codeigniter framework.

Codeigniter is one of the Framework and the basic principles of MVC architecture. Codeigniter Insert Update Delete Follows example code.

Codeigniter Insert Update Delete
Codeigniter Insert Update Delete

Codeigniter Insert Update Delete

View


<div id="codeignitersample" class="modal fade" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">

                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="myModalLabel">New Entry</h4>
                            </div>
                            <div class="modal-body">
                                <div id="testmodal" style="padding: 5px 20px;">
                                    <form id="antoform" class="form-horizontal " role="form">


                                      <input type="hidden" disabled="true" class="form-control" id="txtDate" name="txtDate">
                               
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">Task Title</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" id="title" name="title">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">Description</label>
                                            <div class="col-sm-9">
                                                <textarea class="form-control" style="height:55px;" id="descr" name="descr"></textarea>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default antoclose" data-dismiss="modal">Close</button>
                                <button type="button" id="btnAddTask" class="btn btn-primary antosubmit">Save changes</button>
                            </div>
                        </div>
                    </div>
                </div>


Model


<?php

defined('BASEPATH') or exit('Error!');

class Appmodel extends CI_Model
{

public function __construct(){
# code...
parent::__construct();
$this->load->database();
}
public function addTask($title,$details,$date){

$task_details = array('task_id'=>mt_rand(1,9999999999),
  'task_name'=>$title,
  'task_details'=>$details,
  'date'=>$date
            );
return $this->db->insert('task',$task_details);
}
public function allTask(){

$sql = $this->db->get("task");
return $sql->result_array();
}
public function deleteTask($id){
$this->db->where('task_id',$id);

return $this->db->delete('task');

}
public function editTask($title,$details,$id){
$new_taskdetails=array('task_name'=>$title,'task_details'=>$details);
$this->db->where('task.task_id',$id);
return $this->db->update('task',$new_taskdetails);
}
}


Controller


<?php
defined('BASEPATH') or exit('Error!');
/**
*
*/
class App extends CI_Controller{

private $data;

public function __construct(){

parent::__construct();
$this->load->library(array('session','form_validation','mydateconverter'));
$this->load->helper(array('url'));
$this->load->model('appmodel');

}
public function index(){
$this->data['page_title'] = "Dev2tricks ! ";
$this->load->view('ui/tpl/head',$this->data);
$this->data['tasks']=$this->appmodel->allTask();
$this->load->view('ui/home',$this->data);


}
//ajax event!
public function addtask(){

   $response = $this->appmodel->addTask($this->input->post('title'),
$this->input->post('description'),
$this->mydateconverter->convertDate($this->input->post('date')));
echo $response;

}
//ajax event!

public function deletetask(){
$response = $this->appmodel->deleteTask($this->input->get('id'));
echo $response;
}

//ajax event!
public function editask(){
$response = $this->appmodel->editTask($this->input->post('title'),
$this->input->post('description'),
$this->input->post('id')
);
echo $response;
}

}


Database File


CREATE TABLE `cii` (
  `id` int(11) NOT NULL auto_increment,
  `cii_id` int(11) NOT NULL,
  `cii_name` varchar(255) NOT NULL,
  `cii_details` text NOT NULL,
  `date` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
)

Introduction to codeigniter

Introduction to codeigniter

Introduction to Codeigniter
Introduction to Codeigniter

Introduction


Codeigniter is one of the Framework and the basic principles of MVC architecture. MVC Format Module Control View It will show you how a basic codeigniter application is constructed in step-by-step fashion.

  1. Codeigniter is Most Used Module Active Record basic database queries.
  2. Form Validation is Used
  3. Site Url Passing Method Routhing basics

why use codeigniter

Useful Documentation

Codeigniter most advantage CI over any other framework is it's documentation.  CIs documentation is 10 times better than other framework documentation I have come cross and I strongly think thats because CI is backed by a company and not just a community.  EllisLab, the company behind CI, takes a lot of pride in CI and they have big plans for it and thats why they don’t have a problem in spending the time that is necessary to come up with quality documentation for the user community.

Database abstraction and more.

Every decent framework has a database abstraction layer nowadays and CI is no exception. You can easily create insert, update and delete statements without needing to write raw SQL. Handle connections to multiple databases within one application and connect to any of the following database types: MySQL (4.1+), MySQLi, MS SQL, Postgre, Oracle, SQLite, or ODBC. CI also lets you manipulate your database like add/remove columns from tables, create new tables and remove old ones using it’s new database forge library.

No installation necessary.

Believe it or not, one of the hardest things I have experienced with trying new frameworks is installing them. I am not a fan of UNIX command line so I tend to look for tools that I can install and use by just uploading files to a directory. CI fits this requirement nicely. No need for PEAR packages or server modifications to get the framework up and running. Just upload the files to your server and your off.

MVC Architecture

The model, view, controller architecture is nothing new. It seems like all the coding frameworks are MVC nowadays, and if they aren’t it can be configured easily. I have had experience building large apps the procedural way and every time they end up with unmanageable spaghetti code. The MVC way of doing things offers nice code separation and keeps things clean. Some frameworks force you to do things by the books but CI lets you use MVC in a way that makes sense you. If that means ignoring models all together then so be it. Codeigniter Module