Calling a database view in Yii using Active Record Calling a database view in Yii using Active Record mysql mysql

Calling a database view in Yii using Active Record


It should work fine in the same way as with tables. Just use the view name when you generate the model.

Please read Joshua's answer and learn how to add primary Key into the OOP model for views.


I am not having the same experience and this comment is for those who are having trouble.

Using a mysql view with some joins and calculations I get the following error..

app\\models\\db\\WarComplete must have a primary key.

I resolved this by adding...

public static function primaryKey(){    return ['id'];}

... to my model override.