我从交易市场获取实时价格并将其保存在数据库中。因此,使用 $model->save() 函数来插入或更新任何数据。我不知道我哪里做错了。结果显示‘错误’。我不知道为什么会出错以及如何解决它。
公共(public)函数 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]
最佳答案
不要在 else
中回显错误,而是按照
print_r($model->getErrors());
这会将您重定向到正确的错误
关于php - 模型->保存()在 Yii 中不起作用 -> 显示 ' error ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46817820/