Skip to content

Instantly share code, notes, and snippets.

@yuya-matsushima
Created May 1, 2011 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuya-matsushima/950327 to your computer and use it in GitHub Desktop.
Save yuya-matsushima/950327 to your computer and use it in GitHub Desktop.
MY_Modelの魔法の言葉の話し
<?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