Я только начал изучать CodeIgniter
. Но я застрял в какой-то момент. После 7+ часов работы и поиска в Google я решил спросить здесь. Я пытаюсь обновить базу данных, но не могу выйти из нее. После ввода данных мои данные не обновляются. Вот мой код;
Takvim_Model.php
function __construct() {
parent::__construct();
}
public function insert($data) {
if ($this->db->insert('takvim', $data)) {
return true;
}
}
public function delete($roll_no) {
if ($this->db->delete('takvim', 'roll_no = '.$roll_no)) {
return true;
}
}
public function update($data,$old_roll_no) {
$this->db->set($data);
$this->db->where('roll_no', $old_roll_no);
$this->db->update('takvim', $data);
}
}
?>
Takvim_View.php
<!DOCTYPE html> <html lang = "en"> <head>
<meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
<a href = "<?php echo base_url(); ?>index.php/takvim/add_view">Add</a>
<table border = "1">
<?php
$i = 1;
echo "<tr>";
echo "<td>Sr#</td>";
echo "<td>Roll No.</td>";
echo "<td>Name</td>";
echo "<td>Start Time</td>";
echo "<td>Stop Time</td>";
echo "<td>Update</td>";
echo "<td>Delete</td>";
echo "<tr>";
foreach($records as $r) {
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$r->roll_no."</td>";
echo "<td>".$r->name."</td>";
echo "<td>".$r->start_time."</td>";
echo "<td>".$r->stop_time."</td>";
echo "<td><a href = '".base_url()."index.php/takvim/update/"
.$r->roll_no."'>Update</a></td>";
echo "<td><a href = '".base_url()."index.php/takvim/delete/"
.$r->roll_no."'>Delete</a></td>";
echo "<tr>";
}
?>
</table>
Takvim_Controller.php
<?php
class Takvim_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->database();
}
public function index() {
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->helper('url');
$this->load->view('Takvim_view', $data);
}
public function add_event_view() {
$this->load->helper('form');
$this->load->view('Takvim_add');
}
public function add_event() {
$this->load->model('Takvim_model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time')
);
$this->Takvim_model->insert($data);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function update_event_view() {
$this->load->helper('form');
$roll_no = $this->uri->segment('3');
$query = $this->db->get_where("takvim",array("roll_no"=>$roll_no));
$data['records'] = $query->result();
$data = array('records' => $data['records']);
$this->load->view('Takvim_update',$data);
}
public function update_event(){
$this->load->model('Takvim_Model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time'),
'stop_time' => $this->input->post('stop_time')
);
$old_roll_no = $this->input->post('old_roll_no');
$this->Takvim_Model->update($data,$old_roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function delete_event() {
$this->load->model('Takvim_Model');
$roll_no = $this->uri->segment('3');
$this->Takvim_Model->delete($roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
} ?>
Takvim_Update.php
<!DOCTYPE html><html lang = "en"> <head> <meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
<form method = "" action = "">
<?php
echo form_open('Takvim_controller/update');
echo form_hidden('old_roll_no',$records[0]->roll_no);
echo form_label('Roll No.');
echo form_input(array('id'=>'roll_no',
'name'=>'roll_no','value'=>$records[0]->roll_no));
echo "
";
echo form_label('Name');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->name));
echo "
";
echo form_label('Start Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->start_time));
echo "
";
echo form_label('Stop Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->stop_time));
echo "
";
echo form_submit(array('id'=>'submit','value'=>'Edit'));
echo form_close();
?>
</form>
routes.php
$route['takvim'] = "Takvim_controller";
$route['takvim/add'] = 'Takvim_controller/add_event';
$route['takvim/add_view'] = 'Takvim_controller/add_event_view';
$route['takvim/update/(\d+)'] = 'Takvim_controller/update_event_view/$1';
$route['takvim/delete/(\d+)'] = 'Takvim_controller/delete_event/$1';