YII2 How to Call Controller Action From the View -


i have function in controller manipulates data way wanted. want call function in index.php file in view. how do that?

in controller

function actiontesting($params){     ..... } 

how can call in view like..

 <?php    echo $this->testing($params);//calling unknown method: yii\web\view::testing() ?> 

you should not call controller actions view. think violates mvc pattern.

as error, it's clear, $this in view refers yii\web\view, not controller , testing method doesn't exist there.

there similar question asked before, here possible solution (credits manesh):

yii::$app->runaction('controller/action', ['param1' => 'value1', 'param2' => 'value2']); 

this not enough call controller action usual method call because events need applied, etc.

i don't recommend use approach, it's better move logic component / model depending on type of it.