【问题标题】:Code Igniter overriden DB Active RecordCodeigniter 覆盖 DB Activerecord
【发布时间】:2011-06-15 11:28:37
【问题描述】:

我想重写 Active Record 类(至少它的一些功能)。我在“应用程序”文件夹中名为“数据库”的文件夹中创建了一个名为 spj_DB_active_rec.php 的文件,但它不起作用。

类名是 spj_DB_active_record

<?php
class spj_DB_active_record extends CI_DB_active_record {

    function update($table = '', $set = NULL, $where = NULL, $limit = NULL) {
        if (is_array($set) && empty($set['modified'])) {
            $this->load->helper('date');
            $data['modified'] = date('Y-m-d H:i:s',now());
        }

        log_message('debug','TEST UPDATE '.date('Y-m-d H:i:s',time()));

        return parent::update($table, $set, $where, $limit);
    }

    function insert($table = '', $set = NULL) {
        if (is_array($set) && empty($set['modified'])) {
            $this->load->helper('date');
            $data['modified'] = date('Y-m-d H:i:s',now());
        }
        if (is_array($set) && empty($set['created'])) {
            $this->load->helper('date');
            $data['created'] = date('Y-m-d H:i:s',now());
        }

        log_message('debug','TEST INSERT '.date('Y-m-d H:i:s',time()));
        return parent::insert($table, $set);
    }
}

【问题讨论】:

  • 你能分享一些关于什么不起作用的信息吗?你希望它做什么?
  • 你在代码中看到了。如果尚未设置,则应该将“修改”和“创建”添加到插入/更新中。首先它应该记录测试消息。
  • @Damien Pirsy 我不调用文件。它只是一个来自 codeigniter 的覆盖文件(或者它应该是)。
  • 我认为这是你的问题。在下面检查我的答案。

标签: php database codeigniter overriding


【解决方案1】:

这对你来说可能是个新闻,但 CodeIgniter 2.0 并不正式支持扩展核心 Active Record 类。因此,您想要做的是(不幸的是)不是通过在磁盘上的某个位置放置一个从它扩展的类来“完全可能”。

但是你可以试试这个workaround。

猜你喜欢
  • 2015-07-30
  • 2015-04-16
  • 1970-01-01
  • 2010-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-22
  • 1970-01-01
相关资源
最近更新 更多