PHP Codeigniter framework.
Codeigniter is one of the Framework and the basic principles of MVC architecture. Codeigniter Insert Update Delete Follows example code.
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
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>
<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);
}
}
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;
}
}
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`)
)
`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`)
)