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.
- 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();
}
- 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;
}
}
-
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(); } }
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?