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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改