Creating model from string - equivalent to old CActiveRecord::model function

Hi,

In Yii 1 you could generate a model instance from a string eg




$modelName = 'Page';

$id = 1;


$model = CActiveRecord::model($modelName)->findByPk($id);




in Yii2 I can’t find an equivalent to the model method - does anyone how to do this?

Many thanks!




$modelName = 'app\models\Page';

$modelName::findOne($id);



doh, that was easy lol - many thanks!

You should read this ;)

Thanks Timmy - have been through the docs - just getting a bit tangled up with how things were done in the old days :rolleyes: