0

I am building a zend framework web app around the mysql sakila db. I have been able to display the basic films table details in a films view. this table contains among other columns, a 'language_id' and an 'original_language_id' columns that reference a language table. I have set up the table relationships correctly in my models. I am not sure how to display the language (not the id's) in my films view - how and where do I use the model relationships to display the langauge names in my view? at the controller level? here's part of my films controller:

    class FilmsController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $this->view->title = 'Films';
        $this->view->headTitle($this->view->title);
        $films = new Application_Model_DbTable_Films();
        $this->view->films = $films->fetchAll();

here's part of the view where I show the table

   <td><?php echo $this->escape($film->title);?></td> 
<td><?php echo $this->escape($film->description);?></td>
<td><?php echo $this->escape($film->release_year);?></td> 
<td><?php echo $this->escape($film->language_id);?></td>

. . .

Marcin
  • 215,873
  • 14
  • 235
  • 294
Pete_ch
  • 1,301
  • 2
  • 28
  • 39

1 Answers1

2

To get parent row for your films (e.g. language), you can use:

$languageRow = $filmRow->findParentRow('MODEL_FOR_LANGAUGE_TABLE');

Simillarly to get dependant rowset of the film table (e.g. actors), you can use:

$actorRowset = $filmRow->findDependentRowset('MODEL_FOR_ACTORS_TABLE');

To simplify this you could define custom film db_row that would have a method called, e.g. getLanguage(). More about this you can read here. This way to get e.g. a language name you could just do: $filmRow->getLanguage()->name;.

Community
  • 1
  • 1
Marcin
  • 215,873
  • 14
  • 235
  • 294