View all Model data in Zend Framework 1

Asked

Viewed 89 times

0

The way I have in this explore I get only 1 dice from each table, but I would like to understand how to print all.

 // Criamos o objeto do model da tabela 'carros'. 
 $carrosModel = new Application_Model_Carros();

 // Pegamos o carro de 'id' igual a 3.
 $carros = $carrosModel->fetchRow('id = 3');

 /*
 Estava pensando em criar esse foreach pegar o ID de cada um
 e fazer tipo igual fetchRow, mas minhas tentativas não deram certo.

 foreach ($carros as $carro)
 {
    $id = $carro->id;    
 }
 */

 // Aqui pegamos os campos das cores relativos ao carro de 'id'
 // igual a 3.
 $cores = $carros->findDependentRowSet('Application_Model_Cores');

 echo $carros->modelo;
 foreach($cores as $cor)
 {
    echo " -> " . $cor->cor;
 }

1 answer

1

I don’t quite understand your question. If you want to access the data of all cars you should use the method fetchAll(); Type

$select = $carrosModel->select(); 
$select->orderBy("id ASC");
$carros = $carrosModel->fetchAll($select);
foreach($carros as $carro){
echo $carro->id;
}

Give more details if not this.

Browser other questions tagged

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