CI(CodeIgniter)模型用法实例分析(2)

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once APPPATH.'core/database/ActiveRecord.php'; class MY_Model extends ActiveRecord { public function __construct($group_name = '') { $this->initDb($group_name); parent::__construct(); } protected function initDb($group_name = '') { $db_conn_name = $this->getDbName($group_name); $CI = & get_instance(); if(isset($CI->{$db_conn_name}) && is_object($CI->{$db_conn_name})) { $this->db = $CI->{$db_conn_name}; } else { $CI->{$db_conn_name} = $this->db = $this->load->database($group_name, TRUE); } } private function getDbName($group_name = '') { if($group_name == '') { $db_conn_name = 'db'; } else { $db_conn_name = 'db_'.$group_name; } return $db_conn_name; } } /* End of file MY_Model.php */ /* Location: ./application/core/MY_Model.php */

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/1287b98f6a8c7c092af0ee980a2df374.html