P
P
Padre2017-07-12 19:57:40
Yii
Padre, 2017-07-12 19:57:40

How to check if an entry has been added in Yii2?

Let's use a simple code:

$user = new Users();
        $user ->name= 'Alex';
        $user ->age= '44';
        $user ->save();

How to find out the number of rows modified (added) by this query?
PDO has $count = $user->rowCount();
Here I tried to do this, but Yii threw an error:
Unknown Method - yii\base\UnknownMethodException
Calling unknown method: app\models\Country::rowCount()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lumore, 2017-07-12
@yii16

if($user->save()) {
   return 'Пользователь создан';
} else {
   return 'Ошибка';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question