当我登录管理页面时,我收到错误404 Page Not Found。找不到您请求的页面。 我想通过以下代码登录管理页面:
控制器:
public function index()
{
$data = $this->data;
$this->load->view('admin/index.php',$data);
}
public function login()
{
$data = $this->data;
$username=$this->input->post("username");
$password=$this->input->post("password");
print_r($username); die();
$this->load->model('admin/grocery_crud_model');
$res=$this->grocery_crud_model->check_login($username,$password);
if($res==1)
{
$this->load->view('admin/main.php',$data);
}
else
{
$data['error']="Invalid Username or Password";
$this->load->view('admin/index.php',$data);
}
}
public function home()
{
$data = $this->data;
$this->load->view('admin/index.php',$data);
}
Grocery crud model:
public function check_login($username,$password)
{
$query=$this->db->query(" select * from tbl_register where username='".$username."' and password='".$password."'");
return $query->num_rows() ;
}
查看:
<form name="login" action="<?php echo site_url('admin/admin/login');?>" method="post">
<div class="col-md2"></div>
<div class="col-md8 lgmid">
<div class="error" style="margin-left:10px; margin-top:35px;"><?php //echo $error;?></div>
<div class="lg"><label><b>Username</b></label> <input type="text" name="username" class="textbox"></div>
<div class="lg"><label><b>Password</b></label> <input style="margin-left:2px" type="password" name="password" class="textbox"><br/></div>
<div align="center"><input type="submit" class="lgbtn" value="Submit" /></div>
</div>
<div class="col-md2"></div>
</form>
在模型中,使用的表是tbl_register。该模型是否有任何问题。请为此问题提供解决方案。
答案 0 :(得分:1)
您无法加载视图,就像这样
$this->load->view('admin/index.php',$data); //wrong
您必须加载不带文件扩展名
$this->load->view('admin/index',$data); //correct
所以 文件夹结构 将是
application
controllers
model
view
admin
index
和在模型中
public function check_login($username,$password)
{
$query=$this->db->query(" select * from tbl_register where username='$username' and password='$password'");
$result = $query->result_array();
$count = count($result);
return $count;
}
编辑01
并采取表格行动
将此更改为
action="<?php echo site_url('admin/admin/login');?>"
此
action="<?php echo base_url().'admin/admin/login'?>"
按 在base_url()
中使用url
加载autoload.php
库
答案 1 :(得分:0)
删除此
$config['base_url'] = 'http://localhost/ASoft/Projects/AutoGadi2Amy';
$config['base_url'] = '';
just keep empty