CodeIgniter错误-在null上调用成员函数

万丹·昆巴特

我的表单可以在提交时加载Auth控制器类的登录方法,而我的AuthData模型具有身份验证功能。现在,当用户提交表单时,我得到了错误?

警告是-

遇到PHP错误
严重性:通知
消息:未定义的属性:Auth :: $ AuthData
文件名:controllers / Auth.php行号:21

回溯:
文件:C:\ xampp \ htdocs \ trials \ application \ controllers \ Auth.php行:21函数:_error_handler
文件:C:\ xampp \ htdocs \ trials \ index.php行:315函数:require_once

错误遇到未捕获的异常
类型:错误
消息:在null上调用成员函数authenticate()
文件名:C:\ xampp \ htdocs \ trials \ application \ controllers \ Auth.php行号:21

回溯:
文件:C:\ xampp \ htdocs \ trials \ index.php行:315功能:require_once

这是我的控制器

<?php
//defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller {
public function index()
{
    $this->load->view('welcome_message');
    $this->load->model('AuthData');
    $this->load->helper('url');
    // needed ???
    $this->load->database();
}

public function login()
    {
        $user = $this->input->post('username');
        $pass = $this->input->post('password');
        $input = array( 'username'=>$user, 'password'=>$pass);

        $data['loggedIn'] = "no";
        $chk = $this->AuthData->authenticate($input);
        if($chk)
            redirect('Sample/success');
        else
            redirect('Sample/failed');


        //$this->load->view('home/contact');
    }   
}

我的模特

<?php
//session_start();
class AuthData extends CI_Model {

    public function __construct()
    {
            $this->load->database();
    }

    public function authenticate($input=NULL)
    {
        $query = $this->db->query('SELECT * FROM user');
        $rows = $query->result_array();
        foreach($rows as $check)
        {
            if($input['password']==$check['password'])
            {
                if($input['username']==$check['usernmae'])
                {
                    //session_start();
                    $_SESSION['login'] = "T";
                    $_SESSION['username'] = $input['username'];
                    //is it unsafe to keep password?
                    $_SESSION['password'] = $input['password'];
                    return true;
                    //maybe break here is redundant,but dont want risk
                    break;
                }
            }
        }
        return false;
    }   
}
?>

和form_open在视图中

<?php echo form_open('auth/login', ['class' => 'form-signin', 'role' => 'form']); ?>

另外,如果有关系,我已经删除了index.php。

安东尼

正如@aynber正确指出的那样,该函数无法全局使用AuthData模型。

您的2种选择是:1-按照@ wolfgang1983的说明在config / autoload.php脚本中自动加载,或者2:设置构造函数

public function __construct(){
$this->load->model('Authdata');
}

然后,它将在整个控制器中可用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Codeigniter 3致命错误:在null上调用成员函数database()

错误:在 null 上调用成员函数 setPayrollperiodid()

错误:在null上调用成员函数add()

Codeigniter:消息:在 null 上调用成员函数 line()

Laravel-错误:在null上调用成员函数fullName()

PHP CURL致命错误:在null上调用成员函数getAttribute()

错误消息:在null上调用成员函数render()

登录时出现错误“在 null 上调用成员函数 prepare()”

致命错误:在null上调用成员函数hasAttribute()

PHP - 在 null 上调用成员函数 query() - 错误

如何修复“在null上调用成员函数update()”错误?

错误:在Drupal 8中在null上调用成员函数uuid()

致命错误:在null上调用成员函数prepare()

致命错误:在null上调用成员函数query()

致命错误:在null上调用成员函数query()(Laravel 5.2)

Laravel 5.5 - “在 null 上调用成员函数 sync()”错误

未捕获的错误:在null上调用成员函数query()

Mysqli:致命错误:在null上调用成员函数prepare()

laravel 5.7错误:在null上调用成员函数save()

PHP 未捕获错误:在 null 上调用成员函数 query(),

致命错误:在 null 上调用成员函数 add()

错误:在数组上调用成员函数

致命错误:在非对象上调用成员函数prepare(),调用prepare语句的对象不为null

我在更新函数上遇到了这个错误(在 null 上调用成员函数 getClientOriginalExtension())

致命错误:未捕获的错误:在 wordpress 中在 null 上调用成员函数 insert()

致命错误:未捕获错误:在null上调用成员函数select()

使用PDO时出现错误:致命错误:在null上调用成员函数prepare()

致命错误:未被捕获的错误:在null上调用成员函数prepare()

致命错误:未被捕获的错误:在null上调用成员函数query()