我正在尝试在提交HTML表单后执行PHP类,但我的浏览器显示它无法打开指定地址。 这是我的表格:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>Logins</title>
</head>
<body>
<div id='login_form'>
<form action='<?php echo base_url();?>Login/process' method='post' name='process'>
<h2>User Login</h2>
<br />
<label for='username'>UsernameTest</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课程:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller{
function __construct(){
parent::__construct();
}
public function index(){
// Load our view to be displayed
// to the user
$this->load->view('login_view');
}
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
$this->index();
}else{
// If user did validate,
// Send them to members area
redirect('home');
}
}
}
?>
该类位于Controller文件夹中,表单位于View文件夹
中感谢的
答案 0 :(得分:1)
如果您在配置文件中将网站配置为http://www.mywebsite.org
,则行:
<form action='<?php echo base_url();?>Login/process' method='post' name='process'>
将呈现为:
<form action='http://www.mywebsite.orgLogin/process' method='post' name='process'>
这显然不是您的意图,因为http://www.mywebsite.orgLogin/process
甚至不是有效的网址。要在CodeIgniter中呈现URL,请使用site_url()
:
<form action='<?php echo site_url('Login/process');?>' method='post' name='process'>
除此之外,您可能还需要检查其他两个问题:
/Login/process
页面不存在/home
页面不存在答案 1 :(得分:0)
首先回复或转储您的base_url()
以查看其中的内容,或使用site_url()
。我通常使用'/'
作为/controller_name/function
,请使用“登录”而不是“登录” ”。
答案 2 :(得分:0)
当我手动编写以下URL时,它会起作用:
localhost:8888/CodeIgniter-3.0.0/index.php/Login/process
但是没有使用表单重定向。
<form action='<?php echo site_url('Login/process/');?>' method='post' name='process'>
由于