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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵