I’m getting started with Zend Framework. I have been doing some tutorials here and there.
In one of my views, i have this block of code:
<?php foreach($this->Instruments as $Instrument) : ?>
<tr>
<td><?php echo $this->escape($Instrument->nom);?></td>
<td><?php echo $this->escape($Instrument->idtypeofinstrument);?></td>
<td>
</td>
</tr>
<?php endforeach; ?>
idtypeofinstrument is a foreign key, right now it just displays the id. I’d like to display something else more explicit for the user.
My tables:
+------------------+
| typeofinstrument |
+------------------+
| id | -- primary key
| typeofinstrument | -- what I want to display
+------------------+
+--------------------+
| instrument |
+--------------------+
| id | -- primary key
| name |
| idtypeofinstrument | -- foreign key
+--------------------+
The simple way to do this, not really correct but simple.
To do it in a more correct manner would require the use of a mapper, ORM or some other solution to map the data in the table to an instrument object.
With the goal being for your original code to return the data you want.
To understand further check out:
http://phpmaster.com/building-a-domain-model/
http://phpmaster.com/integrating-the-data-mappers/
These articles helped me a lot with understanding mappers.