简体   繁体   English

登录代码点火器代码不起作用

[英]Login codeigniter code not working

Please help. 请帮忙。 My codeigniter login using sessions is not logging nor able to logout. 我使用会话登录的Codeigniter无法登录,也无法注销。

When i click to login it gives me a 404 Page Not Found 当我单击登录时,它给了我一个404页面未找到

The page you requested was not found. 未找到您所请求的页面。

My controller truckerlogin_ctrl 我的控制器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');
    }


     }

     ?>

**My Model - truckerlogin_model.php ** **我的模型-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;
       }
      }



     }
     ?>

My view truckerlogin_view.php 我的看法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>

Trucker Account truckeraccount_ctrl.php 卡车司机帐户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);  


     }
    }

     ?>

Trucker Account Model truckeraccount_model.php 卡车司机账户模型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();

      }

     }
     ?>

In your 'truckerlogin_ctrl' you have this redirect: 在您的'truckerlogin_ctrl'中,您具有以下重定向:

redirect('truckeraccount_view');

But you haven't any controller named truckeraccount_view if you want to set a view, use the load->view() instead or create the controller.. 但是,如果要设置视图,则没有任何名为truckeraccount_view的控制器,而是使用load->view()或创建控制器。

In the view part truckerlogin_view.php , you haven't set the form tag: 在视图部分truckerlogin_view.php ,您尚未设置表单标签:

<form action='url' name='form' ... > << here you link the view with the controller <form action='url' name='form' ... > <<在这里,您将视图与控制器链接

You only have the submit button (if you don't implement with JS it wouldn't work). 您只有提交按钮(如果您不使用JS实现,将无法使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM