Created
May 1, 2011 07:38
-
-
Save yuya-matsushima/950327 to your computer and use it in GitHub Desktop.
MY_Modelの魔法の言葉の話し
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MY_Model extends CI_Model | |
{ | |
protected $tbl; | |
public function __construct() | |
{ | |
parent::__construct(); | |
// Model名からテーブル名取得 | |
$this->tbl = substr(strtolower(get_class($this)), 0, -6); | |
} | |
public function insert($data, $tbl = '') | |
{ | |
//$dataに応じて0返すとかthrowするとかはお好みで | |
$tbl = empty($tbl) ? $this->tbl : $tbl; | |
$this->db->query($this->db->insert_string($tbl, $data)); | |
return $this->db->insert_id(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment