2016-06-30 57 views
0

我在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> 
+0

显示你的路由器,你是否删除了index.php?您在浏览器中搜索的Stud_controller中的什么网址 –

+0

也请查看roytuts.com/category/codeigniter/ – user3470953

+0

@FreddySidauruk是的。我删除了index.php,并在基础url中添加了url。我已将默认控制器设置为Stud_controller。这是默认的控制器 –

回答

0
  1. 检查,如果您没有设置默认的路由器配置/ router.php。
  2. 在相同的情况下设置文件名和类名,如果将它们设置为小写,则更好。
+0

作家你的类名称就像acbController不要使用下划线。 –

+0

我确实设置了默认控制器。不过它在你的视图文件显示空白页 –

+0

.">Add ,你可以请共用一个屏幕截图; 将以下代码放入控制器文件中的 以上的索引函数中 var_dump(“good”); 退出; $ query = $ this-> db-> get('stud'); –

0

娜迦,你BASE_URL应该是这样的例子

base_url("blog/post/123"); 

而且,采取的index.php出来的URL。 “.base_url()。”index.php/stud/edit /“”

删除期间和index.php。你从来没有在你的URL中使用.php