Answer the question
In order to leave comments, you need to log in
How to call a controller method whose name is in a variable?
Yii2. The bottom line is that I want to get the names of the controllers from the database and call one method from them. I try:
public function actionIndex()
{
$plugin = 'FilesController';
$data['files'] = $plugin::thumbnail();
return $this->render('index', ['data' => $data]);
}
public function actionIndex()
{
$data['files'] = FilesController::thumbnail();
return $this->render('index', ['data' => $data]);
}
$plugin = 'app\modules\cabinet\controllers\FilesController';
$data['files'] = $plugin::thumbnail();
Answer the question
In order to leave comments, you need to log in
Why not do so?
$plugin = __NAMESPACE__ . '/FilesController';
$data['files'] = $plugin::thumbnail();
$plugin = __NAMESPACE__ . '/FilesController';
$data['files'] = call_user_func([$plugin, 'thumbnail']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question