douhao2721 2018-08-25 06:14
浏览 54
已采纳

从控制器重定向到登录视图在Codeigniter中发生错误

Hi I'm new to php and code igniter. what I tried is to get login info from view and validated user and need to send a message to user whether login details are incorrect.

Controller Code :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function __construct() {
    parent::__construct();

    $this->load->model('login_model');
    $this->load->helper('form'); 
    $this->load->helper('url');

    }
    public function index()
    {
        //$this->load->helper('url');
        $this->load->view('login/login');
    }
    public function login_check()
    {
        //$this->load->view('hello');
        //echo "directed";
    $user_id = $this->input->post('usernm');
    $userPassword = $this->input->post('passwordd'); 
    //echo $user_id.' and'.$userPassword;
    $var = $this->login_model->check_login($user_id);
    $status = 0;
    if(empty($var))
    {
        echo "Invalid user";
        $status = 0;
    }
    else
    {
    //echo var_dump($var);
    $username = $var->username;
    //echo $username;
        $status = 1;

    }
  $this->load->helper('url');
  redirect('login/login');
  //$this->load_>view('login\login');// at this point it does not redirect to login page and instead of that displaying error 404.page not found.
//echo $status;

    }

}

Same url ,earlier loaded when it called from from index function but fi it is calling from login check()function does not directed to the view and displaying error 404 page not found.

Any assistance regarding this world be a great help. Thanks a Lot!

  • 写回答

2条回答 默认 最新

  • douping1581 2018-08-25 06:59
    关注

    You need to write redirect('welcome'); instead of redirect('login/login');. Because login/login is the view page and you are trying to redirect direct on view without using controller. So you have two option which I had written bellow.

    1. redirect('welcome');
    2. $this->load->view('login/login');

    My suggestion is please choose 1st option because 2nd option already you have implemented in first one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用