ZF1 foreach correct in view

1

I have the following controller (ZF1) where I get the ID of everyone from a table and with that ID I use to "filter" and get specific data from another table is a relationship by ID.

$tabFerias = new Srh_Model_Ferias("srh");
$agendados = $tabFerias->getAll();

foreach ($agendados as $servidor)
{
    $this->id = $servidor->srh_periodo_aquisitivo_sca_pessoa_idPessoa;

    $tabPessoa = new Sca_Model_Pessoa("sca");
    $this->view->pegaId = $tabPessoa->getPessoa($this->id);

}

If I create another foreach inside the controller it brings the correct data as I want.

foreach ($pegaId as $agendado)
{
    $this->matricula = $agendado->matricula;
    $this->nome = $agendado->nome;
} 

But I want to send this foreach to the view so I do the following in the same:

  <?php foreach ($this->pegaId as $agendado) : ?> 

        <tbody>
            <tr>
                <td><?php echo $agendado->matricula; ?></td>
                <td><?php echo $agendado->nome; ?></td>
            </tr>
        </tbody>

  <?php endforeach; ?>

But it only comes from a user. How do I change this?

functions of the model:

public function getAll()
    {
        $resultado = $this->fetchAll();
        return $resultado;
    }   

public function getFerias($id)  
    {   
        $resultado = $this->find($id);
        return $resultado;
    }

Att.

    
asked by anonymous 24.07.2014 / 22:14

1 answer

1

Change your foreach and use an auxiliary array:

$pegaId = array();
foreach ($agendados as $servidor)
{
    $this->id = $servidor->srh_periodo_aquisitivo_sca_pessoa_idPessoa;

    $tabPessoa = new Sca_Model_Pessoa("sca");
    $pegaId[] = $tabPessoa->getPessoa($this->id);

}
$this->view->pegaId = $pegaId;
    
06.08.2014 / 20:04