ZF-3352: Zend_View_Helper_Partial does not support an object to be passed in - issue ZF-2431 reopened.
Description
This issue is related/duplicate of ZF-2431
[Based on ZF 1.5.2 code]
Such call: Zend_View_Helper_PartialLoop::partialLoop($viewScript, Zend_Db_Table_Rowset $rowset) will couse this:
public function partialLoop($name = null, $module = null, $model = null)
{
// ...
// ...
if (is_object($model) && method_exists($model, 'toArray')) {
$model = $model->toArray();
}
to be always true, because Zend_Db_Table_Rowset which is stored in $model here implements toArray() method. This method does this:
public function toArray()
{
// @todo This works only if we have iterated through
// the result set once to instantiate the rows.
foreach ($this->_rows as $i => $row) {
$this->_data[$i] = $row->toArray();
}
return $this->_data;
}
So all rows in rowset are converted to array.
The side effect of this behaviour is that: $this->partialLoop()->setObjectKey('myObject')->partialLoop($viewScript, Zend_Db_Table_Rowset $rowset);
won't populate row object inside $this->myObject, which behaviour is in fact implemented in Zend_View_Helper_Partial::partial():
if (!empty($model)) {
if (is_array($model)) {
$view->assign($model);
} elseif (is_object($model)) {
if (null !== ($objectKey = $this->getObjectKey())) {
$view->assign($objectKey, $model); // <== This line is never reached, despite we have called setObjectKey('myObject')
} elseif (method_exists($model, 'toArray')) {
$view->assign($model->toArray());
} else {
$view->assign(get_object_vars($model));
}
}
}
Commentig out line 71 in lib/Zend/View/Helper/PartialLoop.php, it is "$model = $model->toArray();" makes object accessible insiade partial view via $this->myObject.
Cheers!
Comments
Posted by Piotr Czachur (zimnyx) on 2008-05-29T08:04:37.000+0000
Issue text with formatted code.
Posted by Matthew Weier O'Phinney (matthew) on 2008-05-29T08:44:13.000+0000
Duplicates ZF-3350
Posted by Matthew Weier O'Phinney (matthew) on 2008-05-29T08:47:19.000+0000
Scheduling for next mini-release (per ZF-3350)
Posted by Matthew Weier O'Phinney (matthew) on 2008-07-22T10:03:48.000+0000
Resolved with ZF-3350