/ Published in: PHP

URL: http://doesthismakesense.org/projects/crud/
Expand |
Embed | Plain Text
<?php /** * CRUD Model * @author Joshua Kendall <[email protected]> * @package Models * @date 01/10/2009 * @revision 3 * @access public * @desc CRUD Model for CI sites * @doc http://doesthismakesense.org/projects/crud/ */ class crud_model extends Model { /** * Constructor Method * */ public function __construct() { parent::__construct(); } /** * Create * @param $table * @param $data * @param $sql_modifiers * @return */ { foreach($sql_modifiers as $modifier) { { $this->db->$modifier[0]($modifier[1]); } else { { $this->db->$modifier[0]($modifier[1], $modifier[2]); } else { $this->db->$modifier[0]($modifier[1], $modifier[2], $modifier[3]); } } } $query = $this->db->insert($table, $data); return; } /** * Read * @param $table * @param $sql_modifiers * @return Object */ { foreach($sql_modifiers as $modifier) { { $this->db->$modifier[0]($modifier[1]); } else { { $this->db->$modifier[0]($modifier[1], $modifier[2]); } else { $this->db->$modifier[0]($modifier[1], $modifier[2], $modifier[3]); } } } $query = $this->db->get($table); return $query->result(); } /** * Update * @param $table * @param $data * @param $sql_modifiers * @return */ { foreach($sql_modifiers as $modifier) { { $this->db->$modifier[0]($modifier[1]); } else { { $this->db->$modifier[0]($modifier[1], $modifier[2]); } else { $this->db->$modifier[0]($modifier[1], $modifier[2], $modifier[3]); } } } $query = $this->db->update($table, $data); } /** * Delete * @param $table * @param $params * @param $sql_modifiers * @return */ { foreach($sql_modifiers as $modifier) { { $this->db->$modifier[0]($modifier[1]); } else { { $this->db->$modifier[0]($modifier[1], $modifier[2]); } else { $this->db->$modifier[0]($modifier[1], $modifier[2], $modifier[3]); } } } $query = $this->db->delete($table); } /** * Execute SQL File * @param $file_name * @return */ public function execute_sql_file($file_name) { foreach($file as $query) { $result = $this->db->query($query); } return; } }
Comments

You need to login to post a comment.
I really love this model,. thanks for sharing
I really love this model,. thanks for sharing