0

I have a problem with Zend Framework. I created a plugin that requests some data from a database.

<?php
class Blog_Plugin_Navigation extends Zend_Controller_Plugin_Abstract {
    public function routeShutdown(Zend_Controller_Request_Abstract $request) {
        $navigation = new Application_Model_NavigationMapper();

        $view = Zend_Layout::getMvcInstance()->getView();
        $view->navigation = $navigation->fetchAll();
    }
}

In my layout.phtml I use this:

<ul>
    <?=$this->partialLoop('navigation-item.phtml', $this->navigation)?>
</ul>

When I use print_r to print out the array I get the values from my database, but if I visit my website I just get no values. navigation-item.phtml looks like this:

<li><a href="<?=$this->url?>"><?=$this->text?></a></li>

I just get this:

<li><a href=""></a></li>

Where is my mistake? Would be really nice, if someone could help me. :) Thanks in advance.

anisie
  • 69
  • 6
  • What do you get for `var_dump($navigation->fetchAll())` and then what do you get for `var_dump($this->url, $this->text)` in the partial template? – drew010 Apr 24 '12 at 20:46
  • For `var_dump($navigation->fetchAll())` I get an array with my values I want to show and for `var_dump($this->url, $this->text)` I get NULL values. :/ – anisie Apr 24 '12 at 21:01
  • Ok, I wonder if you also get `NULL` for `$this->navigation` in your `layout.phtml` script? I would think the variable is assigned there, so maybe its getting lost somehow with the partialLoop. Are your values inside the `$navigation` array objects or array? What do you get if you try `=$this['url']?>` and `=$this['text']?>`? – drew010 Apr 24 '12 at 21:18

1 Answers1

2

Repalce

<?=$this->partialLoop('navigation-item.phtml', $this->navigation)?>

with

<?=$this->partialLoop('navigation-item.phtml', $this->navigation)->setObjectKey('model')?>

Then replace

<li><a href="<?=$this->url?>"><?=$this->text?></a></li>

with

<li><a href="<?=$this->model->url?>"><?=$this->model->text?></a></li>
Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • 1
    +1. I always end up passing an array: `$this->partial('my_partial.phtml, array('model' => $mydata));` Using `setObjectKey()` feels better to me. Thanks! – David Weinraub Apr 25 '12 at 05:26