C
C
Carlos Rodriguez2015-01-17 11:17:11
Yii
Carlos Rodriguez, 2015-01-17 11:17:11

Yii2. Closure. How to get the id of the added field?

return (new \common\models\Company([
            'user_id' => $user_id,
            'region_id' => $this->region_id,
            'city_id' => $this->city_id,
            'address' => $this->address,
            'subdomain' => $this->subdomain,
        ]))->save();

how to get the id of the newly added post?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LAV45, 2015-01-18
@LAV45

$model = new \common\models\Company([
    'user_id' => $user_id,
    'region_id' => $this->region_id,
    'city_id' => $this->city_id,
    'address' => $this->address,
    'subdomain' => $this->subdomain,
]);
$model->save();

echo $model->id; // ID нового элемента

return $model;

A
Artem Filatov, 2015-01-17
@crtv

Yii::$app->db->lastInsertID;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question