Correct ZF1 foreach in view

Asked

Viewed 49 times

1

I have following controller (ZF1) where I get everyone’s ID from a table and with this ID I use to "filter" and take specific data from another table is a relationship by ID let’s say so.

$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 there 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 anyway:

  <?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 only information comes from one 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.

  • It seems to me that you are recording the data more than once in the same property. Should always come the last result right?

  • The syntax in the view echo is quite wrong

  • I’m sorry, I don’t understand. =\

1 answer

1

Changes your foreach and uses 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;

Browser other questions tagged

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