2014-12-20 36 views
0
$usrmodel = new Tempcategory; 

    $temp_id = $tempid; 
    $ct_id  = $ctid; 


    $inarray=array();   

    if(is_array($inarray)) 
    { 
     foreach(array($ct_id) as $catid)    
     { 
      $inarray[]=array('temp_id'=>$temp_id,'ct_id'=>$catid); 

     } 

     if(count($inarray)>0) 
     { 
      GeneralRepository::insertSeveral($usrmodel->tableName(),$inarray); 

     } 

    } 

我有三個表添加一個數組的每個值作爲每行..如何用分貝在YII

  1. 類別 CT_ID初級 ct_name
  2. 模板 temp_id初級 t_name

  3. tempcategory temp_cid primar Ÿ CT_ID FK temp_id FK

我需要在數據庫保存如下

temp-id ct_id 
1  1 
1  2 
1  3 

回答

0
$usrmodel = new Tempcategory; 

    $temp_id = $tempid; 
    $ct_id  = $ctid; 

    $new = explode(" ", $ct_id); 
    // print_r($new); 

    $inarray=array(); 

     foreach($new as $catid)    
     {     
      $inarray[]=array('temp_id'=>$temp_id,'ct_id'=>$catid);    
     } 
     if(count($inarray)>0) 
     { 
      GeneralRepository::insertSeveral($usrmodel->tableName(),$inarray); 
     } 

它解決了.........