每次我点击登录提交按钮,它都会转到“找不到对象”错误404!我一直在看我的代码几个小时,找不到合适的解决方案。请帮忙!谢谢!
login_controller.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index(){
$this->load->view('template/header');
$this->load->view('login_view');
echo "<script> alert('x'); </script>";
}
public function login(){
$email = $this->input->post('email');
$password = $this->input->post('password');
$successful = $this->login_model->login($email,$password);
if($successful){
$this->home();
} else {
echo "<script> alert('x'); </script>";
}
}
function home(){
if($this->session->userdata('email') != ""){
// $this->load->view('template/header');
// $this->load->view('home_view');
echo "<script> alert('y'); </script>";
} else {
// $this->load->view('template/header');
// $this->load->view('login_view');
echo "<script> alert('n'); </script>";
}
}
}
?>
login_view.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<link href="<?php echo base_url(); ?>public/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo base_url(); ?>public/css/custom.css" rel="stylesheet">
<div class="container">
<form class="form-login" method="post" action="login_controller/login">
<img src="<?php echo base_url(); ?>public/img/q_logo.png">
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>
</form>
</div>
login_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_model extends CI_Model {
function login($email,$password){
$this->db->where("email",$email);
$this->db->where("password",$password);
$query=$this->db->get("users");
if($query->num_rows()>0){
foreach($query->result() as $rows){
$newdata = array(
'email' =>$rows->email,
'firstname' =>$rows->firstname,
'lastname' =>$rows->lastname
);
}
$this->session->set_userdata($newdata);
return TRUE;
} else {
return FALSE;
}
}
}
?>
答案 0 :(得分:2)
Go application&gt; config&gt;的config.php
确保正确输入基本网址,最后/
例如:
$config['base_url'] = 'http://192.168.7.123/admin/';
请注意最后的/
。
我希望这会有所帮助:)
答案 1 :(得分:0)
您的代码看起来正确。你的观点存在吗?你输入了正确的名字?我想这是你的问题。
使用form_open()打开表单标记。