search

Home  >  Q&A  >  body text

php - 能不能给讲讲 用的框架里的Data模式是怎么把数组转换成对象的?

如:

1

2

3

4

5

6

// 从model中取出数据

$questions = $this->questionModel->listQuestions();

// 将数组放入迭代器

$this->questions = new Data_Question($questions);

// 展现模板

$this->view->render('questions.php');

到View中我们就可以操作Data_Question对象了

1

2

3

4

<?php foreach($questions as $q): ?>

<h2><a href="<?php $q->url(); ?>"><?php $q->title(); ?></a></h2>

<p><?php $q->summary(100, '...'); ?></p>

<?php endforeach; ?>

我想知道这个Data_Question是如何实现的

PHP中文网PHP中文网2938 days ago395

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-10 14:25:26

    Class XXX implements Iterator, ArrayAccess, Countable{}

    reply
    0
  • PHP中文网

    PHP中文网2017-04-10 14:25:26

    貌似重写一下ArrayObject就可以实现,谢谢啦

    reply
    0
  • Cancelreply