Zend框架 - 视图数组 - 对象表示法

时间:2013-06-17 04:08:16

标签: php zend-framework

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

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

这可能吗?

2 个答案:

答案 0 :(得分:1)

唯一真正的选择是在以这种方式使用之前将数组转换为对象。

  <?php foreach ($this->results as $r): ?>
  <div>

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

答案 1 :(得分:1)

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

 <?php foreach ($this->arrUserList as $data) { ?>
                 <?php $data = (object)$data; ?>

  <td><?php echo $this->escape($data->userName); ?></td>

如果我能为您提供更多帮助,请告诉我。