2017-10-18 93 views
2

我将实时价格表交换市场来源并保存在数据库中。因此,使用$ model-> save()函数来插入或更新任何数据。我不知道我犯了什么错误。结果显示“错误”。我不知道为什么它是错误的,以及如何解决它。model-> save()在Yii中不工作 - >显示'错误'

公共职能的actionIndex(){

for ($i=1; $i <=3 ; $i++) { 
     for ($j=1; $j <=4 ; $j++) { 
      for ($k=1; $k <=4 ; $k++) { 

       echo '<pre>'; 
       $coin_id = $i; 
       $market_1 =$j; 
       $market_2 =$k; 

       $fee = 0.0025; 

       $price_1 = PriceUs::model()->find('market_id='.$market_1.' AND coin_id='.$coin_id.' ORDER BY id DESC'); 
       $price_2 = PriceUs::model()->find('market_id='.$market_2.' AND coin_id='.$coin_id.' ORDER BY id DESC'); 

       $profit = ( (100/( ($price_1->offer_usd)/(1-$fee))) * ( ($price_2->bid_usd) * (1-$fee)) ) - 100 ; 

       $model=new Oneway; 
       $model->create_at=date("Y-m-d H:i:s"); 
       $model->coin_id=$coin_id; 
       $model->market_id1=$market_1; 
       $model->market_id2=$market_2; 
       $model->profit_oneway=$profit; 

       if($model->save()) 
       { 
        echo 'ok'; 
       } 
       else 
       { 
        echo 'error'; 
       } 
      } 
     } 
    } 
}[enter image description here][1] 

结果显示该 确定 确定 错误 确定 确定 错误 确定 错误 确定 确定 错误 。 。 。 这意味着一些结果可以保存但有些不能。的 enter image description here

回答

0

代替else呼应错误,请为

print_r($model->getErrors()); 

这将您重定向到正确的错误