Call a controller action for the views

2

I'm using Yii2 and doing a site project where one of the features is to list the movies bound to a specific user. I already have a method to associate the movies with the accounts and one that does the inner join of the tables.

(Actions Code):

public function actionAssociarFilme($idFilme){
    $model = new FilmeHasCompra();
    $model->Filme_idFilme = $idFilme;
    $model->Usuario_idUsuario = Yii::$app->user->identity->idUsuario;
    $model->save();
    return $this->goBack();
}
public function actionListarFilme(){
    $resultado = Filme::find()
    ->innerJoin('filme_has_compra', 'filme_has_compra.Filme_idFilme=Filme.idFilme')
    ->where('filme_has_compra.Usuario_idUsuario=:idusuario',['idusuario'=>Yii::$app->user->identity->idUsuario]) ->all();

    return $this->render('tables',['resultado'=>$resultado]);


}

}

The question is how to call this action ListarFilme in the view, because when I try to call it it appears a unknown method error

    
asked by anonymous 15.12.2017 / 18:03

2 answers

0

First import the controller responsible for the action.

And try something like this:

Yii::$app->runAction('controller/action', ['primeiroParametro' => 'primeiroValor', 'segundoParametro' => 'segundoValor']);

But I advise you not to break the MVC scheme, so you could use a Widget or a ViewHelper .

    
20.12.2017 / 16:26
0
<?=Yii::$app->controller->renderPartial('listarFilme', ['param1'=>1111, ''=> 22222]) ?>

However you need to change the "render" of the ActionLstarFilme "renderPartial" otherwise you will also include the "layot" twice

return $this->renderPartial('tables',['resultado'=>$resultado]);
    
01.02.2018 / 17:24