views:

15

answers:

2

Hello I have problem.

Message: PartialLoop helper requires iterable data

Stack trace:
#0 [internal function]: Zend_View_Helper_PartialLoop->partialLoop('partials/ListaK...', Object(Model_Klasy))
#1 C:\xampp\php\PEAR\Zend\View\Abstract.php(342): call_user_func_array(Array, Array)
#2 [internal function]: Zend_View_Abstract->__call('partialLoop', Array)
#3 C:\xampp\htdocs\inzynierka\application\views\scripts\klasy\lista.phtml(9): Zend_View->partialLoop('partials/ListaK...', Object(Model_Klasy))
#4 C:\xampp\php\PEAR\Zend\View.php(108): include('C:\xampp\htdocs...')
#5 C:\xampp\php\PEAR\Zend\View\Abstract.php(880): Zend_View->_run('C:/xampp/htdocs...')
#6 C:\xampp\php\PEAR\Zend\Controller\Action\Helper\ViewRenderer.php(897): Zend_View_Abstract->render('klasy/lista.pht...')
#7 C:\xampp\php\PEAR\Zend\Controller\Action\Helper\ViewRenderer.php(918): Zend_Controller_Action_Helper_ViewRenderer->renderScript('klasy/lista.pht...', NULL)
#8 C:\xampp\php\PEAR\Zend\Controller\Action\Helper\ViewRenderer.php(957): Zend_Controller_Action_Helper_ViewRenderer->render()
#9 C:\xampp\php\PEAR\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#10 C:\xampp\php\PEAR\Zend\Controller\Action.php(523): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#11 C:\xampp\php\PEAR\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('listaAction')
#12 C:\xampp\php\PEAR\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#13 C:\xampp\php\PEAR\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#14 C:\xampp\php\PEAR\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#15 C:\xampp\htdocs\inzynierka\public\index.php(26): Zend_Application->run()
#16 {main} 

I'm trying to pass this data:

    object(Model_Klasy)#76 (4)
{ 
   ["_id":"Model_Klasy":private]=> int(1) 
   ["_rokRozpoczecia":"Model_Klasy":private]=> int(2010) 
   ["_nazwa":"Model_Klasy":private]=> string(2) "1a" 
   ["_Wychowawca":"Model_Klasy":private]=> int(9) 
} 

Here is Action:

$modelLista = new Model_KlasyMapper();
$this->view->listaKlas = $modelLista->listaKlas();

And View:

echo $this->partialLoop('partials/ListaKlas.phtml', $this->listaKlas);

How solve this problem ? Probably it is easy but I'm tired :/

+1  A: 

Your object needs to support a an implement an iterable interface like ArrayAccess or IteratorAggregate (Though i think even something as simple as Traversable will work). Or you could make all the members public (shudder).

prodigitalson
I know but how to do that ?
WooCaSh
Implement all the methods of one of the appropriate interfaces and add the implementation tot he class like: `class Model_Klassy implements ArrayAccess { /* class body */ }` Check out this DevZone Article for a crash course: http://devzone.zend.com/article/2565
prodigitalson
Fatal error: Class Model_KlasyMapper contains 4 abstract methods and must therefore be declared abstract or implement the remaining methods (ArrayAccess::offsetExists, ArrayAccess::offsetGet, ArrayAccess::offsetSet, ...) in C:\xampp\htdocs\inzynierka\application\models\KlasyMapper.php on line 48
WooCaSh
Umm yeah.. you have to implement those methods man... you can just declare the interface and then it works...
prodigitalson
I am confused. I start with Zend 2 months ago and also learning OOPHP :/ Can u help me more ?
WooCaSh
er **cant** not **can** :-) Read the artical i posted link to... Whatever interface you choose to use you need to implement ALL or its methods. The documentation for the given interface will tell you what each method is supposed to do - you just need to right the code to make it do that. Heres another good one specifically for ArrayAccess if thats what you want to use: http://www.phpro.org/tutorials/Introduction-to-SPL-ArrayAccess.html
prodigitalson
problem solved i show u my solution but not now 6:00 AM in my country :)
WooCaSh
One thing worth noting: if the object passed to the `partialLoop()` implements a `toArray()` method, it will get called (with no parameters) prior to iteration. This bit me once while trying to pass a `Doctrine_Collection` to the `partialLoop()`. In that case, the `toArray()` with no params defaults to a _recursive_ `toArray()` which, while understandable, was not desirable. I suppose I could have overridden the `toArray()` method to set different defaults, but in the end, I just bailed on the `partialLoop()` and did the looping directly in my view script.
David Weinraub
A: 

All it was wrong because of one bracer :) I hate it when miss something :P After it I can display it after little modification:

   <?php foreach ($this->listaKlas as $dane) :  ?>
                <td><?php echo $dane->getNazwa(); ?></td>
                <td><?php echo $dane->getRokRozpoczecia(); ?></td>
                <td><?php echo $dane->getWychowawca(); ?></td>
etc.
WooCaSh