我在CODEIGNITER中完成了這個CRUD操作。但是,當我嘗試運行該程序時,我得到一個空白頁。而且我無法知道錯誤是什麼。任何幫助,將不勝感激。我附上了下面的代碼。使用codeigniter的CRUD操作
Stud_controller.php `
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Stud_controller extends CI_Controller {
function __construct(){
parent:: __construct();
$this->load->helper('url');
$this->load->database();
}
public function index()
{
$query = $this->db->get('stud');
$data['records'] = $query->result();
$this->load->helper('url');
$this->load->view('Stud_view', $data);
}
public function add_student_view(){
$this->load->helper('form');
$this->load->view('Stud_add');
}
public function add_student(){
$this->load->model('Stud_Model');
$data = array(
'Roll_No' => $this->input->post('Roll_No'),
'Name' => $this->input->post('Name')
);
$this->Stud_Model->insert($data);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->view('Stud_view',$data);
}
public function update_student(){
$this->load->model('Stud_Model');
$data = array(
'Roll_No' => $this->input->post('Roll_No'),
'Name' => $this->input->post('Name')
);
$old_Roll_No = $this->input->post('old_Roll_No');
$this->Stud_Model->update($data,$old_Roll_No);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load->view('Stud_view',$data);
}
public function delete_student(){
$this->load->model('Stud_Model');
$Roll_No = $this->uri->segment('3');
$this->Stud_Model->delete($Roll_No);
$query = $this->db->get("stud");
$data['records'] = $query->result();
$this->load-view('Stud_view',$data);
}
}
?>`
Stud_Model.php
<?php
Class Stud_Model extends CI_Model {
function __construct(){
parent:: __construct();
}
public function insert($data) {
if($this->db->insert("stud", $data)){
return true;
}
}
public function delete($Roll_No){
if($this->db->delete("stud", "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("stud", $data);
}
}
?>
Stud_view.php
<html>
<head>
<title>Student</title>
</head>
<body>
<a href = '<?php echo base_url(); ?>
index.php/stud/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>Edit</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><a href = '".base_url()."index.php/stud/edit/"
.$r->Roll_No."'>Edit</a></td>";
echo "<td><a href = '".base_url()."index.php/stud/delete/"
.$r->Roll_No."'>Delete</a></td>";
echo "<tr>";
}
?>
</table>
</body>
</html>
顯示你的路由器,你是否刪除了index.php?您在瀏覽器中搜索的Stud_controller中的什麼網址 –
也請查看roytuts.com/category/codeigniter/ – user3470953
@FreddySidauruk是的。我刪除了index.php,並在基礎url中添加了url。我已將默認控制器設置爲Stud_controller。這是默認的控制器 –