Call to undefined method app\models\Message::model()

M_Idrees picture M_Idrees · Jan 22, 2016 · Viewed 8.5k times · Source

I am new with Yii2, using Gii tool,I have created the model and CRUD components for simple 'Message' class with one field 'content' mapped to tbl_message.

I am getting error, When trying to retrieve one message object by using findByPk function as follows:

$message = Message::model()->findByPk(4);

Error message:

Call to undefined method app\models\Message::model()

Answer

Salem Ouerdani picture Salem Ouerdani · Jan 22, 2016

This would be enough :

 $message = Message::findOne(4)

More details and custom cases may be found here.