Answer the question
In order to leave comments, you need to log in
Why does not write data to the yii2 database?
For some reason the data is not being written to the database.
$transfer = new TransferOperations();
$transfer->from_user = $fromUser;
$transfer->to_user = $toUser;
$transfer->money = $money;
$transfer->created_at = time();
$transfer->save();
public static function tableName()
{
return 'transfer_operations';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['created_at', 'to_user', 'from_user'], 'required'],
[['created_at'], 'integer'],
[['money'], 'number'],
[['to_user', 'from_user'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'created_at' => 'Created At',
'to_user' => 'To User',
'from_user' => 'From User',
'money' => 'Money',
];
}
Answer the question
In order to leave comments, you need to log in
Good afternoon.
First, do a check
if($transfer->save()){
// какое-то действие
}
else{
// показать все ошибки
}
use yii\behaviors\TimestampBehavior;
public function behaviors()
{
return [
TimestampBehavior::className()
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question