我仍然在CodeIgniter中学习。
我想在我的codeigniter应用程序中创建一个登录表单。 我的观点部分如下:
<html>
<head>
<title>Jotorres Login Screen | Welcome </title>
</head>
<body>
<div id='login_form'>
<form action="<?php echo base_url();?>Login/process" method='post' name='process' enctype="multipart/form-data">
<h2>User Login</h2>
<br />
<?php if(! is_null($msg)) echo $msg;?>
<label for='username'>Username</label>
<input type='text' name='username' id='username' size='25' /><br />
<label for='password'>Password</label>
<input type='password' name='password' id='password' size='25' /><br />
<input type='Submit' value='Login' />
</form>
</div>
</body>
</html>
控制器部分:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login controller class
*/
{
class Login extends CI_Controller{
function __construct(){
parent::__construct();
}
public function index($msg = NULL){
// Load our view to be displayed
// to the user
$data['msg'] = $msg;
$this->load->view('login_view', $data);
}
public function process(){
// Load the model
$this->load->model('login_model');
// Validate the user can login
$result = $this->login_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$msg = '<font color=red>Invalid username and/or password.</font><br />';
$this->index($msg);
}else{
// If user did validate,
// Send them to members area
redirect('Home');
}
}
}
}
?>
错误讯息:
在此服务器上找不到请求的URL / afi /登录/进程。
如何解决此错误?
模型部分:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/* Author: Jorge Torres
* Description: Login model class
*/
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->userid,
'fname' => $row->fname,
'lname' => $row->lname,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>
答案 0 :(得分:1)
在模型中将 <input
name="searchText"
value={searchText}
onChange={this.onChange}
/>
<div className="col s12">
<input
name="searchText"
value={searchText}
onChange={this.onChange}
/>
</div>
替换为$query->num_rows
,然后重试。
答案 1 :(得分:0)
尝试使用site_url()。 改变:
<form action="<?php echo base_url();?>Login/process" method='post' name='process' enctype="multipart/form-data">
到:
<form action="<?php echo site_url('Login/process');?>" method='post' name='process' enctype="multipart/form-data">
base_url
产生:
而site_url
产生:
答案 2 :(得分:0)
尝试一下
<?php echo form_open('Login/process')?>
解决问题的最佳方法