使用 codeigniter 3 我修改了以下内容。 配置
$config['base_url'] = 'http://demo.xyz.com/xyz/';
$config['log_threshold'] = 4 ;
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
路线
$route['default_controller'] = 'Admin';
控制器
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin_model');
$this->load->helper('url');
$this->load->library("session");
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index()
{
if(!$this->session->userdata('Usr_Mobile_No'))
{
redirect('admin/login');
}
$this->load->view('admin/index');
}
public function check_login()
{
//$name = $this->input->post('name');
$user_type = $this->input->post('user_type');
$mobile = $this->input->post('mobile');
$password = $this->input->post('password');
$admin_panel = $this->input->post('admin_panel');
$new_data = array('Usr_Mobile_No' => $mobile);
$this->session->set_userdata($new_data);
$sql1 = $this->admin_model->check_admin_login($user_type, $mobile, $password);
$redirect = base_url('admin/index');
$data['redirect'] = $redirect;
echo json_encode($data);
}
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
在我的视图文件夹中,我有login.php,其中包含以下代码
<form action="<?php echo base_url('admin/check_login'); ?>" method="post" id="signin_form" autocomplete="off"></form>
提交此表单后,我收到“404 文件或目录未找到”。我认为它试图找到 check_login 这只是一个函数。我的视图文件夹中还有一个index.php。
如何调试这个?请指教。
你就快到了。只需在管理类中添加登录方法即可。
<?php
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
//$this->load->model('admin_model');
$this->load->helper('url');
$this->load->library("session");
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index()
{
if(!$this->session->userdata('Usr_Mobile_No'))
{
redirect('admin/login');
}
$this->load->view('admin/index');
}
public function login()
{
$this->load->view('login');
}
....