【问题标题】:A PHP Error was encountered severity:8192 I'm getting the error遇到 PHP 错误严重性:8192 我收到错误
【发布时间】:2018-12-15 00:23:13
【问题描述】:

与其类同名的方法在 PHP 的未来版本中将不再是构造函数,login 的构造函数严重性已弃用:8192

我在登录 php 文件的第 3 行和第 26 行出现错误 第 26 行错误:未定义属性:login::$load 我收到了错误

我的代码

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

类登录扩展 CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see http://codeigniter.com/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"));
        }

    }


}

} ?>

【问题讨论】:

标签: javascript php codeigniter


【解决方案1】:

希望对您有所帮助:

注意:控制器名称只能以大写字母开头

首先像这样加载url helper:

autoload.php

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

或者像这样加载你的Login控制器:

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

更多:https://www.codeigniter.com/user_guide/helpers/url_helper.html

【讨论】:

  • 你检查我的答案了吗?有用吗?
【解决方案2】:

您不应将类的函数命名为与类相同的名称。你有一个函数login(),类名为login,这会触发第3行的警告。当PHP看到匹配的类和函数名时,它认为该函数是该类的构造函数。但这不是您想要的,这也是您在第 26 行收到错误的原因。

似乎没有任何理由在您的类中使用构造函数。 (除非您确实需要加载帮助程序或其他库)

要解决您的问题,请删除 index() 函数,然后将 login() 重命名为 index()。最后,在类名中使用大写 L。所以改变这个

class login extends CI_Controller {

到这里

class Login extends CI_Controller {

文件名也应该有一个大写的第一个字母,即Login.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-17
    • 2023-01-22
    • 2022-08-05
    • 2019-01-05
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 2015-12-06
    相关资源
    最近更新 更多