model-> save()在Yii中不起作用 - >显示'错误'

时间:2017-10-18 19:30:34

标签: php database for-loop model

我从实时价格形式的交易市场中获取并将它们保存在数据库中。因此,使用$ model-> save()函数来插入或更新任何数据。我不知道我错在哪里。结果显示'错误'。我不知道为什么会出错,以及如何修复它。

public function 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

1 个答案:

答案 0 :(得分:0)

而不是回复else中的错误,执行

print_r($model->getErrors());

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