Calling a controller action for views

Asked

Viewed 347 times

2

I’m using Yii2 and doing a website project where one of the features is to list the movies linked to a specific user. I already have a method to associate movies to accounts and one that makes the tables Inner Join.

(Action 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 appears a Unknown error methodinserir a descrição da imagem aqui

  • 1

    Instead of using code image, copy and paste. So it will be easier for someone to answer the question.

  • Your doubt is how to call the action because the error "Unknown method" is occurring, but you have not made it clear where this action is calling. Could you put the stretch with the line that this error occurs? It will be easier so to find a solution.

2 answers

0

First import controller responsible for action.

And try something like:

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.

0

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.