简体   繁体   English

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

[英]model->save() Not Working In Yii -> Show ' error '

I source the real-time price form exchange market and keep them in database. 我获取实时价格形式交换市场并将其保存在数据库中。 So, was using $model->save() function for inserting or updating any data. 因此,使用$ model-> save()函数插入或更新任何数据。 I don't know where i did mistake. 我不知道我在哪里弄错了。 The result shows ' error '. 结果显示“错误”。 I don't know why it is error and how to fix it. 我不知道为什么是错误以及如何解决。

public function actionIndex() { 公共功能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]

The result show this ok ok error ok ok error ok error ok ok error . 结果显示此ok ok错误ok ok错误ok错误ok ok错误。 . . It's mean some result can save but some cannot. 这意味着某些结果可以保存,但有些则不能。 在此处输入图片说明

instead of echoing the error in else , do as 而不是在else显示错误,而是

print_r($model->getErrors());

this will redirect you to the correct error 这会将您重定向到正确的错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM