dopii22884 2014-10-23 16:31
浏览 23

Codeigniter通用模型函数[关闭]

I am still wondering why CodeIgniter just don't provide generic functions for model which can be generally usefull for creating reading update deleting joining and other manipulation of records to provide facility to the user and save time of the developer i have read about the Grocery CRUD but it is not that what i am looking for i have created two three function which you can call generic functions for retrieving and updating. Here the functions are.

  1. get_records

returns multiple records

function get_records($table, $where=NULL)
    {
        if(!empty($where))
        {
            $this->db->where($where);
        }
        $query=$this->db->get($table);
        if($query->num_rows>0)
        {
            return $query->result();
        }
        else
        {
            return array();
        }
  1. get_record()

return single record

function get_record($table, $where=NULL)
    {
        if(!empty($where))
        {
            $this->db->where($where);
        }
        $query=$this->db->get($table);
        if($query->num_rows>0)
        {
            return $query->row();
        }
        else
        {
            return 0;
        }
    }
  1. Update()

    general purpose function for updation

    function update($table ,$where=NULL ,$data)
    {
        if(!empty($where))
        {
            $this->db->where($where);
        }
        $query=$this->db->update($table,$data);
        if($query)
        {
            return $this->db->affected_rows();
        }
    
    }
    
  2. delete()

//general purpose function for deletion

function delete($table , $where=NULL)
    {
        if(!empty($where))
        {
            $this->db->where($where);
        }
        if($this->db->delete($table))
        {
            return $this->db->affected_rows();
        }
    }

Here are my general function but There is alot more to do with CodeIgniter model because there are alot of functions which can be created as generic functions

My question is do any body have already derived this kind of stuff if yes provide me the link i have been looking for generic functions for CodeIgniter Model because if someone so it would be more time saving rather than writing one by our own

But in www do any body created generic functions for CodeIgniter model?

  • 写回答

2条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题