登录 codeigniter 代码不起作用
Login codeigniter code not working
请帮忙。我使用会话的 codeigniter 登录没有记录也无法注销。
当我点击登录时,出现 404 页面未找到
找不到您请求的页面。
我的控制器truckerlogin_ctrl
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class truckerlogin_ctrl extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->login_validation();
}
public function login_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('truckerid','truckerid','required');
if($this->form_validation->run()){
$data=array(
'truckerid'=>$this->input->post('truckerid'),
'is_logged_in'=>1
);
$this->session->set_userdata($data);
redirect('truckeraccount_view');
}else{
$this->load->view('truckerlogin_view');
}
}
public function validate_credentials()
{
$this->load->model('Truckerlogin_model');
if($this->Truckerlogin_model->can_log_in()){
return true;
}else{
$this->form_validation->set_message('validate_credentials','Incorrect PIN');
return false;
}
}
public function logout()
{
$this->session->sess_destroy();
redirect('truckerlogin_view');
}
}
?>
**我的模型 - truckerlogin_model.php**
<?php
class Truckerlogin_model extends CI_Model
{
public function can_log_in()
{
$this->db->where('truckerid',$this->input->post('truckerid'));
$query=$this->db->get('trucker');
if($query->num_rows()==1){
return true;
}else{
return false;
}
}
}
?>
我的观点truckerlogin_view.php
<div class="login-box-body">
<?php if (isset($message)) { ?>
<h3 style="color:green;">Account created successfully</h3><br>
<h3 style="color:red;"> <?php echo validation_errors(); ?> </h3>
<div class="form-group has-feedback">
<input type="text" class="form-control" name="truckerid" placeholder="Trucker PIN">
<span class="fa fa-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div><!-- /.col -->
<a href="<?php echo site_url('truckereginfo_ctrl/index/') ?>" class="text-center"> Register as a new member</a>
</div>
卡车司机账户truckeraccount_ctrl.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class truckeraccount_ctrl extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Truckeraccount_model');
}
public function index()
{
$this->$data['rows'] = $this->Truckeraccount_model->get_all();
$this->load->view('truckeraccount_view', $this->$data);
}
}
?>
卡车司机账户模型truckeraccount_model.php
<?php
class Truckeraccount_model extends CI_Model{
public function __construct() {
parent::__construct();
}
function get_all()
{
$this->db->select('l_address','d_address','dom');
$q = $this->db->get('consignment');
return $q->result_array();
}
}
?>
在你的 'truckerlogin_ctrl' 中你有这个重定向:
redirect('truckeraccount_view');
但是您没有任何名为 truckeraccount_view
的控制器,如果您想设置视图,请改用 load->view()
或创建控制器..
在视图部分truckerlogin_view.php
,您还没有设置表单标签:
<form action='url' name='form' ... >
<< 这里是你 link 带有控制器的视图
您只有提交按钮(如果您不使用 JS 实现,则无法使用)。
请帮忙。我使用会话的 codeigniter 登录没有记录也无法注销。
当我点击登录时,出现 404 页面未找到
找不到您请求的页面。
我的控制器truckerlogin_ctrl
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class truckerlogin_ctrl extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->login_validation();
}
public function login_validation()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('truckerid','truckerid','required');
if($this->form_validation->run()){
$data=array(
'truckerid'=>$this->input->post('truckerid'),
'is_logged_in'=>1
);
$this->session->set_userdata($data);
redirect('truckeraccount_view');
}else{
$this->load->view('truckerlogin_view');
}
}
public function validate_credentials()
{
$this->load->model('Truckerlogin_model');
if($this->Truckerlogin_model->can_log_in()){
return true;
}else{
$this->form_validation->set_message('validate_credentials','Incorrect PIN');
return false;
}
}
public function logout()
{
$this->session->sess_destroy();
redirect('truckerlogin_view');
}
}
?>
**我的模型 - truckerlogin_model.php**
<?php
class Truckerlogin_model extends CI_Model
{
public function can_log_in()
{
$this->db->where('truckerid',$this->input->post('truckerid'));
$query=$this->db->get('trucker');
if($query->num_rows()==1){
return true;
}else{
return false;
}
}
}
?>
我的观点truckerlogin_view.php
<div class="login-box-body">
<?php if (isset($message)) { ?>
<h3 style="color:green;">Account created successfully</h3><br>
<h3 style="color:red;"> <?php echo validation_errors(); ?> </h3>
<div class="form-group has-feedback">
<input type="text" class="form-control" name="truckerid" placeholder="Trucker PIN">
<span class="fa fa-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div><!-- /.col -->
<a href="<?php echo site_url('truckereginfo_ctrl/index/') ?>" class="text-center"> Register as a new member</a>
</div>
卡车司机账户truckeraccount_ctrl.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class truckeraccount_ctrl extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Truckeraccount_model');
}
public function index()
{
$this->$data['rows'] = $this->Truckeraccount_model->get_all();
$this->load->view('truckeraccount_view', $this->$data);
}
}
?>
卡车司机账户模型truckeraccount_model.php
<?php
class Truckeraccount_model extends CI_Model{
public function __construct() {
parent::__construct();
}
function get_all()
{
$this->db->select('l_address','d_address','dom');
$q = $this->db->get('consignment');
return $q->result_array();
}
}
?>
在你的 'truckerlogin_ctrl' 中你有这个重定向:
redirect('truckeraccount_view');
但是您没有任何名为 truckeraccount_view
的控制器,如果您想设置视图,请改用 load->view()
或创建控制器..
在视图部分truckerlogin_view.php
,您还没有设置表单标签:
<form action='url' name='form' ... >
<< 这里是你 link 带有控制器的视图
您只有提交按钮(如果您不使用 JS 实现,则无法使用)。