ZF1 resulting from the controller in the view

1

I do not understand how in this case to play the values in the project view, it follows the code:

public function indexAction()
{
    $actor = new Application_Model_Actor();
    $resultadoActores = $actor->listarAtor();

    foreach($resultadoActores as $ator)
    {

        $idActor = $ator->actor_id;

        $film_actor = new Application_Model_FilmActor();
        $resultadoFilmeAtores = $film_actor->listarFilmeActorId($idActor);

        foreach ($resultadoFilmeAtores as $filmeAtor)
        {

            $idFilm = $filmeAtor->film_id;

            $film = new Application_Model_Film();
            $resultadoFilmes = $film->listarFilmeId($idFilm);

            foreach ($resultadoFilmes as $filme)
            {
                echo $ator->first_name . " " . $filme->title . "<br/>"; // <-- Esse resultado na view?
            }

        }
    }
}

I tried to do something like: $ this-> view-> movies = $ resultFilmes; and inside the view of the controller create the foreach and assign the values, but without success as well.

    
asked by anonymous 28.05.2014 / 19:20

2 answers

2

I believe the problem is more logical than with Zend Framework 1.

If you make the code you said

$this->view->filmes = $resultadoFilmes;

You will only get the movies of the last actor, which can be no movie.

Rewriting your controller code:

public function indexAction()
{
    $actor = new Application_Model_Actor();
    $resultadoActores = $actor->listarAtor();

    //variável para guardar filmes
    $filmes = array();

    foreach($resultadoActores as $ator)
    {

        $idActor = $ator->actor_id;


        $film_actor = new Application_Model_FilmActor();
        $resultadoFilmeAtores = $film_actor->listarFilmeActorId($idActor);



        foreach ($resultadoFilmeAtores as $filmeAtor)
        {

            $idFilm = $filmeAtor->film_id;

            $film = new Application_Model_Film();
            $resultadoFilmes = $film->listarFilmeId($idFilm);

            foreach($resultadoFilmes as $resultadoFilme){
                $filmes[] = array(
                    'ator' => $ator->first_name, 
                    'filme' => $resultadoFilme->title
                );
            }
        }
    }

    $this->view->filmes = $filmes;
}

In the view, simply:

<?php foreach($this->filmes as $filme): ?>
<?php echo $filme['ator'] ?> <?php echo $filme['filme'] ?>
<?php endforeach?>

Sources:

link

link

    
29.08.2014 / 02:03
1

How are you doing in the view to consume the data? should be of the genre:

<?php foreach($resultadoFilmes as $filme): ?>
<?php echo $filme->title; ?>
<?php endforeach;?>

Did you help?

    
29.07.2014 / 23:52