示例#1
0
function copytable($daoname, $inpid, $pidf = 'pid', $inoldid)
{
    $daoname;
    //modelname
    $inpid;
    //新的上级参数值
    $pidf;
    //上级参数的字[PID]
    $inoldid;
    //原来的上级的值
    $table = D($daoname);
    //引入MODEL
    $tabledata = $table->findall($pidf . '=' . $inoldid);
    //找出相应的数据
    foreach ($tabledata as $creatdb) {
        $creatdb[$pidf] = $inpid;
        $oldid = $creatdb['id'];
        $table->create($creatdb);
        $table->add();
        $newid = $table->getLastInsID();
        copytable('Sys_fields', $newid, 'pid', $oldid);
    }
}
 public function copy()
 {
     if (!empty($_REQUEST['id'])) {
         $project = D('Sys_projects');
         $projectdate = $project->getByid($_REQUEST['id']);
         if ($projectdate['caption'] == '') {
             $this->error('请检查参数是否正确!');
             exit;
         }
         $projectdate['caption'] .= '_new';
         //默认的新的项目会加上_new加以区分
         $projectdate['id'] = '';
         //把ID清空
         $project->create($projectdate);
         //dump($projectdate);
         $project->add();
         $projectid = $project->getLastInsID();
         //取得最新的ID
         copytable('Sys_tables', $projectid, 'pid', $_REQUEST['id']);
         //拷贝本项目下的表及字段
         //防止新生成的公共数据模型不配对
         $tables = D('Sys_tables');
         $tabledate = $tables->where('pid=' . $_REQUEST['id'] . ' and ismodel=1')->findall();
         //找出旧的公共模型
         //dump($tabledate,true,'旧的数据PID');
         foreach ($tabledate as $old_table) {
             $new_caption = $old_table['caption'];
             $new_title = $old_table['title'];
             $old_id = $old_table['id'];
             $tabledate2 = $tables->where("caption='{$new_caption}' and title='{$new_title}' and pid={$projectid} and ismodel=1")->findall();
             //找出新的公共MODEL
             //前提是这两个参数的组合是唯一的
             //dump($tabledate2,true,'新的数据PID');
             foreach ($tabledate2 as $new_tables) {
                 $new_id = $new_tables['id'];
                 //找出了新公共模型的ID
                 $updatetables = $tables->where("datemodelid={$old_id} and pid={$projectid}")->findall();
                 $updatetables['datemodelid'] = $new_id;
                 $updatevar = $tables->create($updatetables);
                 $tables->save();
             }
         }
         redirect(__URL__ . "/index");
     } else {
         $this->error('请检查参数是否正确!');
     }
 }
示例#3
0
文件: common.php 项目: lee99/tpmaker
function copytable($daoname, $inpid, $pidf = 'pid', $inoldid)
{
    //用途拷贝一个表生成一个新表
    $daoname;
    //modelname
    $inpid;
    //新的上级参数值
    $pidf;
    //上级参数的字[PID]
    $inoldid;
    //原来的上级的值
    $table = D($daoname);
    //引入MODEL
    $tabledata = $table->where("{$pidf}={$inoldid}")->findall();
    foreach ($tabledata as $creatdb) {
        $creatdb[$pidf] = $inpid;
        $oldid = $creatdb['id'];
        $creatdb['id'] = '';
        //clear id as null
        $table->create($creatdb);
        $table->add();
        $newid = $table->getLastInsID();
        copytable('Sys_fields', $newid, 'pid', $oldid);
    }
}