Zend Framework

Zend_View_Helper_Partial does not support an object to be passed in.

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.3
  • Fix Version/s: 1.5.0
  • Component/s: Zend_View
  • Labels:
    None
  • Fix Version Priority:
    Should Have

Description

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

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

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

} elseif (is_object($model)) {
          If (method_exists($mode, 'toArray')) {
                   $view->assign($model->toArray());
          } else {
                   $view->assign(get_object_vars($model));
          }
}

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.

} elseif (is_object($model)) {
          If (method_exists($mode, 'toArray')) {
                   $view->assign($model->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.

http://www.nabble.com/Question-about-PartialLoop%28%29-usage-to14739402s16154.html#a14739402

Issue Links

Activity

Hide
Jon Whitcraft added a comment -

Added Patch file.

Show
Jon Whitcraft added a comment - Added Patch file.
Hide
Pádraic Brady added a comment -

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.

Show
Pádraic Brady added a comment - 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.
Hide
Jon Whitcraft added a comment -

I'll do that and see what he says.

Show
Jon Whitcraft added a comment - I'll do that and see what he says.
Hide
Jordan Ryan Moore added a comment -

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

Show
Jordan Ryan Moore added a comment - I think the current implementation is actually the best, and the proper solution is to have your model implement a toArray() method.
Hide
Matthew Weier O'Phinney added a comment -

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).

Show
Matthew Weier O'Phinney added a comment - 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).
Hide
Matthew Weier O'Phinney added a comment -

Functionality added in revision 7782.

Show
Matthew Weier O'Phinney added a comment - Functionality added in revision 7782.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: