demo:
1.表member 和member_data,
2.member为主表设有主键自增,member_data,不设置主键,3.在member_model.class.php里这样设置
defined('IN_PHPCMS') or exit('No permission resources');
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SPEARATOR.'caches_data'.DIRECTORY_SPEARATOR);
pc_base::load_sys_class('model','',0);
class vendor_member_model extends model{
public function __construct(){
$this->db_config = pc_base::load_config('database');
$this->db_setting = 'default';
$this->table_name = 'member';
parent::__construct();
}
//设置函数,主表转换副表
public function set_model($data = '') {
if($data){
$this->table_name = $this->table_name.$data;
}else{
$this->table_name = $this->db_tablepre.'_member';//拼接
}
}
}
4.这里写插入的例子
//$this-->db,实例化member_model.class.php
$memberid=$this->db->insert($zhu,'ture');//返回插入的memberid
$this->db->set_model('_data');
//memberid存如数组¥fu 插入到副表,这样主副表关联了memberid了
$fu['memberid']=$memberid;
$this->db->insert($fu);
$this->db->set_model();
showmessage('添加成功',HTTP_REFERER);