【问题标题】:model->save() Not Working In Yii -> Show ' error 'model->save() 在 Yii 中不工作 -> 显示“错误”
【发布时间】:2018-03-30 18:41:30
【问题描述】:

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

公共函数 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]

结果显示这个 好的 好的 错误 好的 好的 错误 好的 错误 好的 好的 错误 . . . 这意味着有些结果可以保存,但有些不能。

【问题讨论】:

    标签: php database for-loop model


    【解决方案1】:

    不要在else中回显错误,而是按照

    print_r($model->getErrors());
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-05
      • 2021-06-19
      • 2020-09-14
      • 1970-01-01
      • 2014-02-18
      • 2020-09-15
      • 1970-01-01
      • 2021-03-22
      相关资源
      最近更新 更多