Zend框架-视图数组-对象符号


Zend Framework - View Array - Object Notation

我将一个数组传递给视图,其代码如下:

<?php foreach ($this->results as $r): ?>
<div>
<?php echo $this->url(array('id' => $this->escape($r[RecordID]) ....

假设我想使用对象表示法:

<?php foreach ($this->results as $r): ?>
<div>
<?php echo $this->url(array('id' => $this->escape($r->RecordID) ....

这可能吗?

你唯一真正的选择是在这样使用它之前将数组强制转换为一个对象。

  <?php foreach ($this->results as $r): ?>
  <div>
  <?php $r = (object)$r;
        echo $this->url(array('id' => $this->escape($r->RecordID) ....

是的,你可以尝试使用Object在视图中使用对象数组,如

 <?php foreach ($this->arrUserList as $data) { ?>
                 <?php $data = (object)$data; ?>
  <td><?php echo $this->escape($data->userName); ?></td>
如果我还能帮到你,请告诉我。