ZF-2431: Zend_View_Helper_Partial does not support an object to be passed in.

Issue Type: Bug Created: 2008-01-14T12:01:54.000+0000 Last Updated: 2008-05-29T09:07:46.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Jon Whitcraft (sidhighwind) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

Related issues: - ZF-3285

Attachments: - Zend_View_Helper_Partial.patch


I have a model that implements SeekableIterator and Countable so I can use it like an array

When I do a foreach($designs as $design) {} loop I get back the proper value in $design which is an object model containing all the info about a design..but when I do this

<pre class="highlight"> 
<?= $this->partialLoop('view/design.phtml', $this->designs); ?>

I found the problem and noticed that it was doing this when it ran across an object

<pre class="highlight">
} elseif (is_object($model)) {
          If (method_exists($mode, 'toArray')) {
          } else {

What i did to patch it for my code is when there is no toArray method it just assigns the object to a variable named object.

<pre class="highlight">
} elseif (is_object($model)) {
          If (method_exists($mode, 'toArray')) {
          } else {
                   $view->assign('object', $model));

Now i understand this is by no means a final solution but it works for now.

here is a link to the thread on the mailing list where it is being discussed.…


Posted by Jon Whitcraft (sidhighwind) on 2008-01-14T12:02:24.000+0000

Added Patch file.

Posted by Pádraic Brady (padraic) on 2008-01-23T02:41:14.000+0000

Hi Jon,

I'll review the patch - of importance is retaining the current behaviour while allowing specific descendents of some SPL structures a more specialised handling. If you wish the API to be changed without retaining the previous behaviour you will have to suggest this on the mailing list for Matthew's attention since it would create backwards compatibility issues which are best to avoid until the next major revision.

Posted by Jon Whitcraft (sidhighwind) on 2008-01-23T08:04:21.000+0000

I'll do that and see what he says.

Posted by Jordan Ryan Moore (jordanryanmoore) on 2008-01-29T10:42:51.000+0000

I think the current implementation is actually the best, and the proper solution is to have your model implement a toArray() method.

Posted by Matthew Weier O'Phinney (matthew) on 2008-02-04T07:27:42.000+0000

As discussed on fw-mvc, the approach will be the following:

  • Calling partialLoop() without arguments will return the helper object
  • A method, setObjectKey() will be created; this will allow specifying a view variable to which to assign objects
  • If the objectKey is set, it will be used
  • If no objectKey is sett, if the object implements toArray(), that result will be assigned to the view
  • If neither the objectKey is set nor toArray() implemented, the result of get_object_vars() will be assigned to the view

I will tackle this this week (week of 4 Feb 2008).

Posted by Matthew Weier O'Phinney (matthew) on 2008-02-04T10:22:41.000+0000

Functionality added in revision 7782.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.