最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - A PHP Error was encountered severity:8192 I'm getting the error - Stack Overflow

programmeradmin6浏览0评论

Methods with the same name as their class will not be constructors in a future verisons of PHP, login has a deprecated constructor severity:8192

I get an error in line 3rd and 26th line in the login php file 26th line error: undefined property:login::$load I'm getting the error

MY CODE

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

class login extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      .php/wele
 *  - or -
 *      .php/wele/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at /
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/wele/<method_name>
 * @see .html
 */
public function index()
{
    $this->load->view('login');
}
function login(){
    $data ["title"] = "CodeIgniter Simple Login Form with session";
    $this->load->view("login", data);

}
function login_validation(){
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'Kullanýcý Adý', 'required');
    $this->form_validation->set_rules('password', 'password', 'required');
    if($this->form_validation->run())
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $this->load->model('login_model');
        if($this->login_model->can_login($username, $password))
        {

            $session_data = array(

                'username'  => $username

            );
            $this->session->set_userdata($session_data);
            redirect(base_url("login/enter"));

        }else{
            $this->session->flash_data('error' , 'Invalid Username and Password');
            redirect(base_url("login"));

        }
    }else
        {
            $this->login();
    }
    function enter()
    {
        if($this->session->userdata('username') != ''){
            redirect(base_url("dashboard"));

        }else{
                redirect(base_url("login"));
        }

    }


}

} ?>

Methods with the same name as their class will not be constructors in a future verisons of PHP, login has a deprecated constructor severity:8192

I get an error in line 3rd and 26th line in the login php file 26th line error: undefined property:login::$load I'm getting the error

MY CODE

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

class login extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example./index.php/wele
 *  - or -
 *      http://example./index.php/wele/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example./
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/wele/<method_name>
 * @see http://codeigniter./user_guide/general/urls.html
 */
public function index()
{
    $this->load->view('login');
}
function login(){
    $data ["title"] = "CodeIgniter Simple Login Form with session";
    $this->load->view("login", data);

}
function login_validation(){
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'Kullanýcý Adý', 'required');
    $this->form_validation->set_rules('password', 'password', 'required');
    if($this->form_validation->run())
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $this->load->model('login_model');
        if($this->login_model->can_login($username, $password))
        {

            $session_data = array(

                'username'  => $username

            );
            $this->session->set_userdata($session_data);
            redirect(base_url("login/enter"));

        }else{
            $this->session->flash_data('error' , 'Invalid Username and Password');
            redirect(base_url("login"));

        }
    }else
        {
            $this->login();
    }
    function enter()
    {
        if($this->session->userdata('username') != ''){
            redirect(base_url("dashboard"));

        }else{
                redirect(base_url("login"));
        }

    }


}

} ?>

Share Improve this question asked Jul 6, 2018 at 11:37 Atakan Atakan 291 gold badge1 silver badge6 bronze badges 2
  • Possible duplicate of codeigniter returns "Message: Undefined property: Wele::$load" trying to load helper lib – Mosset Jérémie Commented Jul 6, 2018 at 11:45
  • load url helper in your controller or in autoload.php – Pradeep Commented Jul 6, 2018 at 11:46
Add a ment  | 

2 Answers 2

Reset to default 1

Hope this will help you :

Note : Controller name should start with capital letter only

Load url helper first like this :

In autoload.php

$autoload['helper'] = array('url');

Or load in your Login controller like this :

class Login extends CI_Controller 
{
  public function __construct()
  {
    parent::__construct();
    $this->load->helper('url');
   }
}  

For more : https://www.codeigniter./user_guide/helpers/url_helper.html

You should not name a function of a class the same as the class. You have a function login() and the class is named login which triggers the warning on line 3. When PHP sees class and function names that match it thinks the function is the constructor for the class. But that's not what you want and is the reason you get the error on line 26.

There does not seem to be any reason for a constructor in your class. (Unless you really do need to load a helper or other library)

To fix your problem delete the index() function then rename login() to index(). Finally, use an uppercase L in the name of the class. So change this

class login extends CI_Controller {

to this

class Login extends CI_Controller {

The file name should also have an uppercase first letter i.e. Login.php

发布评论

评论列表(0)

  1. 暂无评论