E
E
EVOSandru62015-08-19 09:14:47
Yii
EVOSandru6, 2015-08-19 09:14:47

How to determine the id of the created model in afterSave()?

Greetings!
$this->idwhy is it empty. $this->name is defined.
Yii::app()->db->getLastInsertID();gives an error:
SQLSTATE[42602]: Invalid name: 7 ERROR: invalid name syntax

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2015-08-19
@Akdmeh

If $this->id is empty, then the entry was not saved, in the controller do echo $model->save(); (to check if saving happened) and then if there is no saving - print_r($model->getErrors()); (this will show validation errors). Well, you can also see what request is going through in the debug panel

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question