Is there any way to call controller method in view Yii2 like Yii1 ?
Thanks,
Absar
Is there any way to call controller method in view Yii2 like Yii1 ?
Thanks,
Absar
Not sure if it is good practise… (still a beginner in Yii )
But it works like following:
Examples:
in app/controllers/SiteController.php
public function helloWorld(){
echo "hello world";
}
in app/views/site/anyViewFile.php
echo $this->context->helloWorld();
Or in any other view file:
use app\controllers\SiteController;
echo SiteController::helloWorld();
Regards
Thanks, it works for me
That’s actually a bad practice, if you need logic in the view, use a ViewHelper