【发布时间】:2018-01-12 22:54:14
【问题描述】:
我是新手,正在学习 codeigniter,我正在尝试对从网上下载的 CRUD 进行简单练习,但我被困在路由上。我尽力从以前的帖子和答案中寻找解决方案,但失败了。 这是我的 Stud_controller.php
<?php
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);
}
这是我的 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);
}
}
?>
这是我的 route.php
$route['default_controller'] = 'welcome';
$route['stud'] = "Stud_controller";
$route['stud/add'] = 'Stud_controller/add_student';
$route['stud/add_view'] = 'Stud_controller/add_student_view';
$route['stud/edit/(\d+)'] = 'Stud_controller/update_student_view/$1';
$route['stud/delete/(\d+)'] = 'Stud_controller/delete_student/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
我的配置文件
$config['uri_protocol'] = 'REQUEST_URI';
我的 .htaccess 文件是
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
我的网址 = http://localhost/testing/index.php/stud 但错误是找不到404页面 请帮帮我谢谢
【问题讨论】:
-
在路由器中用小写写你的控制器:$route['stud'] = 'stud_controller';
-
我使用了 'stud_controller 但仍然有同样的错误
-
我认为这是其他类型的错误,而不是 CI 错误。看起来您的服务器无法正常工作,因为我只是测试了您的代码,它看起来不错i.imgur.com/nRDNA4L.png
-
会不会是32bit/64bit不匹配造成的?
标签: codeigniter