php - Codeigniter: problem extending Database Driver
问题描述
Im using Codeigniter 2.x and been trying to extend the database class and followed the wiki but im getting this error:
Fatal error: Uncaught Error: Call to undefined method MY_DB_mysqli_driver::where() in /system/libraries/Session.php on line 218
Error: Call to undefined method MY_DB_mysqli_driver::where() in /system/libraries/Session.php on line 218
On line 218 of /system/libraries/Session.php:
$this->CI->db->where('session_id', $session['session_id']);
My extended class is just the example from the wiki:
<?php
class MY_DB_mysqli_driver extends CI_DB_mysqli_driver
{
public function __construct($params)
{
parent::__construct($params);
log_message('debug', 'Extended DB driver class instantiated!');
}
public function get_first($table)
{
return $this->limit(1)->get($table);
}
}
解决方案
你得到的错误实际上是正确的。我刚刚下载了第 2 版以确保它。
您正在扩展CI_DB_mysqli_driver
您实际添加的内容应该在活动记录库中而不是数据库驱动程序中的时间。
而不是扩展您的CI_DB_driver
创建扩展CI_DB_active_record
并在其中添加get_first
功能。
我必须补充一点,如果您想将这个功能添加到您的核心中,我什至不会费心用它来扩展核心,因为您只是在一行一行地交易,它没有任何好处。
此外,大多数这些扩展都可以在良好的基础模型中完成,而不是侵入核心。
推荐阅读
- spring - 在 Spring Boot 中为 POST 传递 JSessionId 和 CSRF-Token
- java - 删除包含特定单词的 jsonnode
- javascript - 如何在某些 woocomerce 产品上添加按钮
- segmentation-fault - 带有 ktrans 的 mfc42.dll 段错误
- python - 如何嗅探 csv 行分隔符/终止符(csv.Sniffer() 不起作用)
- c# - 预定义任务多次异步返回
- node.js - 验证使用 EC512 签名的 Keycloak JWT 时签名无效
- c# - 带有 Outlook 的 C#...将签名添加到 RTFBody 电子邮件而不是 HTMLBody
- sql-server - 获取适用于 Oracle 和 SQL Server 的上个月的最后一天
- android - 使用SIP建立呼叫时,是主叫还是被叫建立RTP流?