【发布时间】:2020-03-29 18:00:14
【问题描述】:
我目前正在 CodeIgniter 中开发一个系统,该系统需要通过登录和注册作为基础进行用户身份验证,以便使用系统的其余部分。每当我尝试调用 Controller 函数时,我的系统上都会出现 404 Not Found 问题,这在表单提交中尤为普遍。我已经从下面的控制器、模型、视图、路由和 Htaccess 中发布了我的相关代码。我不完全确定导致 404 not found 错误的原因,任何帮助将不胜感激。
控制器:
// handles register page
public function register() {
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = "Register";
$this->form_validation->set_rules('fullname','Full Name','required');
$this->form_validation->set_rules('accountid','Account ID','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('type','Account Type','required');
if ($this->form_validation->run() === FALSE) {
$this->load->view('register', $data);
} else {
$fullname = $this->input->post('fullname');
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
$accounttype = $this->input->post('type');
$this->system->registeruser($username, $password, $fullname, $accounttype);
echo "User Registration Complete";
}
}
型号:
public function registeruser($accountid, $password, $fullname, $accounttype) {
$query = "INSERT INTO users VALUES($fullname','$accountid','$password','$accounttype')";
$this->db->query($query);
}
查看:
<?php
echo form_open('main/register');
echo validation_errors(); ?>
<div id="name-input">
<?php
$data = array(
'name' => 'fullname',
'value' => $this->input->post('fullname'),
'placeholder' => 'Full Name',
'class' => '',
'style' => 'width:100%; padding:0.5em;' );
echo form_input($data);
echo "</p>"; ?>
</div>
<div id="username-input">
<?php
$data = array(
'name' => 'accountid',
'value' => $this->input->post('accountid'),
'placeholder' => 'User ID',
'class' => 'username',
'style' => 'width:100%; padding:0.5em;' );
echo form_input($data);
echo "</p>"; ?>
</div>
<div id="password-input">
<?php
$data = array(
'name' => 'password',
'value' => $this->input->post('password'),
'placeholder' => 'Password',
'class' => 'passwordd',
'style' => 'width:100%; padding:0.5em;' );
echo form_password($data);
echo "</p>"; ?>
</div>
<div id="account-type">
<?php
$options = array(
'student' => 'Student',
'lecturer' => 'Lecturer' );
$data = array(
'name' => 'type',
'style' => 'width:100%; padding:0.5em;' );
echo form_dropdown($data, $options);
echo "</p>"; ?>
</div>
<div id="submit-button">
<?php
$data = array(
'name' => 'register',
'value' => 'Register Account',
'class' => 'register',
'style' => 'width:100%; padding:0.5em;' );
echo form_submit($data); ?>
</div>
<?php echo form_close(); ?>
路线:
$route['main/register'] = 'main/register';
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
上面的所有代码都与我的注册页面/它的相关功能有关,我的系统上目前有多个这些错误,但它们似乎都是同一件事,我想解决一个也可以解决其余的问题。
【问题讨论】:
标签: php codeigniter