gpt4 book ai didi

php - 函数中的 CodeIgniter "Using $this when not in object context"

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

如何替换此代码中的 $this 变量?我知道在函数中使用 $this 是不正确的,但我不知道如何替换它。

function get_dates($id) {
$class = $this->db->query("SELECT * FROM schedule WHERE class_id='".$id."'");
$class = $class->result_array();
return $class;
}

附言。我不会不使用具有标准 php 功能的 mysql,我坚信可以使用 CI 功能解决这个问题。

最佳答案

如果您想从普通函数内部访问 CI 框架,您需要获取 CI 的实例。

function get_dates($id) {
$ci =& get_instance();

$class = $ci->db->query("SELECT * FROM schedule WHERE class_id='".$id."'");
$class = $class->result_array();
return $class;
}

关于php - 函数中的 CodeIgniter "Using $this when not in object context",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27384117/

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