Search code examples
phpactiverecordyii2yii2-basic-app

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


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()

Solution

  • This would be enough :

     $message = Message::findOne(4)
    

    More details and custom cases may be found here.