Answer the question
In order to leave comments, you need to log in
How to call a model on a due date?
Known id and model name in string form. let's say:
use common\models\Article
.....
$id = 2;
$model = 'Article';
$model::findOne($id); //как то так вызвать.
Answer the question
In order to leave comments, you need to log in
You need to get the class by name, and then refer to its static property. Something like this:
$id = 2;
$c_name = 'common\models\Article';
$obj = new $c_name();
$obj::findOne($id);
$c_name = 'common\models\Article';
$obj = Yii::createObject($c_name);
$obj::findOne($id);
$obj = Yii::createObject([
'class' => 'common\models\Article',
'some_attr' => 'алюминий',
]);
$obj::findOne($id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question