Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Passing variable to PartialLoop inside partial view

I have in my view a partial containing a partialLoop. But when I run the page I have the following error message:

Call to a member function countComments() on a non-object in ...'_loop.phtml'

This is how I call my partial from within my view:

echo $this->partial('_post.phtml',$this->post);

where $this->post is a DB retrieved row

This is my partial's content:

MY simplified Partial! 

echo $post->countComments();//the count number is correctly output..
echo  $this->partialLoop('_loop.phtml',$this->object);

This is my partialLoop's content:

echo $this->object->countComments();//no output!

In the bootstrap I have set:

$view->partial()->setObjectKey('object');
$view->partialLoop()->setObjectKey('object');

Is this the right way to call partialLoops from within partials??

P.s. I var_dumped $this->object inside my partial and it is a PostRow OBJECT.I var dumped $this->object into _loop.phtml and I have 5 NULLS (standing for id,title,text,author,datetime fields of my post)

thanks

Luca

like image 936
luca Avatar asked Dec 11 '25 17:12

luca


1 Answers

I think that the reason is that when you pass $this->post into partial view helper like this:

$this->partial('_post.phtml',$this->post);

partial view helper will execute its toArray() method. Hence, your $this->object is an array and you are passing an array to your partialLoop. So, in your partialLoop you are trying to execute countComments() on an array representing your row post object, rather than actual row object.

To avoid this, I would recommend passing variables to partial and partialLoop view helpers using array notation, e.g:

$this->partial('_post.phtml',array('post' => $this->post));

Hope this helps.

like image 122
Marcin Avatar answered Dec 14 '25 13:12

Marcin