How to use the Zend Framework partial loop with objects

I am very confused how to use partialLoop

I am currently using

 foreach ($childrenTodos as $childTodo) { echo $this->partial('todos/_row.phtml', array('todo' => $childTodo)); } 

$childrenTodos is Doctrine\ORM\PersistantCollection , $childTodo is Application\Models\Todo

I tried to do

 echo $this->partialLoop('todos/_row.phtml', $childrenTodos) ->setObjectKey('Application\Models\Todo'); 

But in partial, when I try to access the properties / functions of my Todo class, I cannot force them to always end with the undefined method call Zend_View::myFunction() , when I use $this->myFunction() in partial or if I try $this->todo->getName() , I get a "Member function call getName () for a non-object." How to use partialLoops?

+6
zend-framework zend-view
source share
2 answers

try it

 echo $this->partialLoop('todos/_row.phtml', $childrenTodos) ->setObjectKey('object'); 

Then in partial you can access an object like this

 $this->object 

object is the name of the variable to which the object will be assigned

You can also do this once in your Bootstrap or in another initialization class if you have access to an object like this

 protected function initPartialLoopObject() { $this->_view->partialLoop()->setObjectKey('object'); $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setView($this->_view); } 
+8
source share

I also had a β€œCall to function on non object” error when trying to suggest a syntax, it looks like they changed something in later versions of the Zend Framework. The following works for me on ZF1.12:

 echo $this->partialLoop() ->setObjectKey('object') ->partialLoop('todos/_row.phtml', $childrenTodos); 
+1
source share

All Articles