Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 发生代码点火器错误时,从控制器重定向到登录视图_Php_Html_Codeigniter - Fatal编程技术网

Php 发生代码点火器错误时,从控制器重定向到登录视图

Php 发生代码点火器错误时,从控制器重定向到登录视图,php,html,codeigniter,Php,Html,Codeigniter,嗨,我是php和代码点火器的新手。我尝试的是从视图和验证用户获取登录信息,并需要向用户发送一条消息,说明登录详细信息是否不正确 控制器代码: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { public function __construct() { parent::__construct();

嗨,我是php和代码点火器的新手。我尝试的是从视图和验证用户获取登录信息,并需要向用户发送一条消息,说明登录详细信息是否不正确

控制器代码:

<?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;

    }

您需要编写重定向(“欢迎”)而不是重定向('login/login')。因为login/login是视图页面,您正在尝试在视图上直接重定向,而不使用控制器。你有两个选择,我在下面写的

  • 重定向(“欢迎”)
  • $this->load->view('login/login')
    我的建议是,请选择第一个选项,因为您已经在第一个选项中实施了第二个选项。

    我希望这个选项对您有效

        public function login_check()
        {
           $user_id = $this->input->post('usernm');
           $userPassword = $this->input->post('passwordd'); 
           $var = $this->login_model->check_login($user_id, $userPassword); //pass username and password to your model to authenticate if input exists.
           $data['error'] = '';
        if(!empty($var)) //check if var is not empty
        {
            $this->session->set_userdata($var); //set user_data to var
            redirect('Account/page');  //redirect it to your account or success page
        }else{
             $data['error'] = 'Invalid Username or Password.';
             }
            $this->load->view('login/login',$data); //pass the error notification to your page.
        }
    

    无法重定向,因为您没有控制器名称登录。您试图重定向的是页面视图登录/lgoin。使用重定向(“”);相反,它将重定向到您的欢迎/索引控制器。非常感谢@会话开始。这非常有效,您的额外解释非常有用。再次感谢您的支持!!!:)Welcome@Heshan.非常感谢(‘Welcome’)工作得很好。非常感谢你的帮助!!