gpt4 book ai didi

php - 在 codeigniter 中不在对象上下文中时使用 $this

转载 作者:行者123 更新时间:2023-11-29 17:24:16 24 4
gpt4 key购买 nike

<?php
class Token {
private $CI;

function __construct($param) {
$this->CI =& get_instance();
if($param['flag'] == 1) {
$this->retrieveToken();
$this->validateToken();
}
}

public static function getAuthUserToken($empID) {
$class = $this->CI->db->query('select * from tbl_emp where emp_id ='.$empID);
$class = $class->result_array();
print_r($class);
}
}
?>

我正在 codeigniter 中创建自定义库但是,当我尝试使用数据库执行任何操作时。我收到上述错误消息

我还在 autoload.php 文件中加载了数据库

$autoload['libraries'] = array('database');

最佳答案

这是您的静态方法 getAuthUserToken($empID) 导致了错误。

正如 PHP 文档中关于关键字 Static 所说的那样

Because static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside the method declared as static.

关于php - 在 codeigniter 中不在对象上下文中时使用 $this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51054720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com