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

Issue Type: Bug Created: 2008-05-29T08:02:18.000+0000 Last Updated: 2008-07-22T10:03:48.000+0000 Status: Resolved Fix version(s): - 1.5.3 (28/Jul/08)

Reporter: Piotr Czachur (zimnyx) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

Related issues: - ZF-3350

Attachments: - issue_text_formatted.txt


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)) {
        } 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')) {
            } else {

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.



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

Have you found an issue?

See the Overview section for more details.


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

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