你好,我对codeigniter比较新,请问能否帮我解决一个问题呢?几天前我的代码还可以正常运行,但是现在打开却显示“页面未找到”错误。主要的功能是将用户添加到数据库中。请您帮助我并提供建议。以下是我的model、controller和view代码:
Model文件
Userinsert_model.php
<?php
class Userinsert_model extends CI_Model{
function __construct() {
parent::__construct();
}
function form_insert($data){
$this->db->insert('students', $data);
}
public function datafetch(){
$fetch= $this->db->get('students');
return $fetch->result();
}
}
?>
控制器文件
Userinsert_controller.php(用户插入控制器)
<?php
class Userinsert_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Userinsert_model');
}
function index() {
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('dname', 'Username', 'required|min_length[5]|max_length[15]');
$this->form_validation->set_rules('demail', 'Email', 'required|valid_email');
$this->form_validation->set_rules('dmobile', 'Mobile No.', 'required|regex_match[/^[0-9]{10}$/]');
$this->form_validation->set_rules('daddress', 'Address', 'required|min_length[10]|max_length[50]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('Userinsert_view');
} else {
$data = array(
'Student_Name' => $this->input->post('dname'),
'Student_Email' => $this->input->post('demail'),
'Student_Mobile' => $this->input->post('dmobile'),
'Student_Address' => $this->input->post('daddress')
);
$this->Userinsert_model->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
$this->load->view('Userinsert_view', $data);
}
}
public function fetch() {
$this->load->model('Userinsert_model');
$data["all_data"]= $this->Userinsert_model->datafetch();
$this->load->helper('form');
$this->load->view('Usershow_view', $data);
}
}
?>
查看文件
Userinsert_view.php
<html>
<head>
<title>Insert Data Into Database Using CodeIgniter Form</title>
</head>
<body>
<div id="container">
<?php echo form_open('Userinsert_controller'); ?>
<h1>Insert Data Into Database Using CodeIgniter</h1><hr/>
<?php if (isset($message)) { ?>
<CENTER><h3 style="color:green;">Data inserted successfully</h3></CENTER><br>
<?php } ?>
<?php echo form_label('Student Name :'); ?> <?php echo form_error('dname'); ?><br />
<?php echo form_input(array('id' => 'dname', 'name' => 'dname')); ?><br />
<?php echo form_label('Student Email :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?><br />
<?php echo form_label('Student Mobile No. :'); ?> <?php echo form_error('dmobile'); ?><br />
<?php echo form_input(array('id' => 'dmobile', 'name' => 'dmobile', 'placeholder' => '10 Digit Mobile No.')); ?><br />
<?php echo form_label('Student Address :'); ?> <?php echo form_error('daddress'); ?><br />
<?php echo form_input(array('id' => 'daddress', 'name' => 'daddress')); ?><br />
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<?php echo form_close(); ?><br/>
<div id="fugo">
</div>
</div>
</body>
</html>