Issues

ZF-4141: Zend_View_Helper_PartialLoop forces objects to array conversion when object exposes toArray()

Description

I would like to use the ability exposed in the partialLoop helper to access a Zend_Db_Table_Rowset_Abstract as an object.

Unfortunately, if an object exposes toArray() as one of it's method (which is the case here for Zend_Db_Table_Rowset_Abstract) , then it is automatically converted to an array, instead of offering the possibility to use it as an object instance.

Sample code:

     $this->partialLoop()->setObjectKey('object');
     echo $this->partialLoop('my_partial_view',$rowset_data);

Make sure that $rowset_data is of type Zend_Db_Table_Rowset_Abstract

Comments

I just tested this against svn and it works just fine.

Have you tried using 1.6.1 to see if this problem is fixed.

My Test Table Object


require_once ('Zend/Db/Table/Abstract.php');

class Test extends Zend_Db_Table_Abstract
{
    protected $_name = 'test';
}

Here is what I have in my controller file

 
$db = Zend_Db::factory('mysqli', array('host' => 'localhost', 'username' => 'my_user', 'password' => 'my_passwod', 'dbname' => 'test_db'));
        $test = new Test(array(
            'db' => $db
            ));

        $this->view->results = $test->fetchAll();

Here is what I have in my view:


$this->partialLoop()->setObjectKey('object');
echo $this->partialLoop('index/_pl.phtml', $this->results);

here is what is in my _pl.phtml file


print_r($this->object->toArray());
$name = $this->object->name;
print "Name: " . $name . "
";