• 技术文章 >后端开发 >php教程

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

    2016-06-06 20:51:12原创506

    如:

    // 从model中取出数据
    $questions = $this->questionModel->listQuestions();
    // 将数组放入迭代器
    $this->questions = new Data_Question($questions);
    // 展现模板
    $this->view->render('questions.php');

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

    
    

    title(); ?>

    summary(100, '...'); ?>

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

    回复内容:

    如:

    // 从model中取出数据
    $questions = $this->questionModel->listQuestions();
    // 将数组放入迭代器
    $this->questions = new Data_Question($questions);
    // 展现模板
    $this->view->render('questions.php');

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

    
    

    title(); ?>

    summary(100, '...'); ?>

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

    Class XXX implements Iterator, ArrayAccess, Countable{}

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

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:php
    上一篇:把wordpress文章分享到微博或twitter后, 如果获取weibo或twitter链接下的评论到WP 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 聊聊PHP escapeshellarg函数使用的中文问题• PHP原生类的总结分享• 分享PHP函数使用小工具(附代码示例)• PHP安全编码总结(经验分享)• 非常全面!PHP常见漏洞代码总结!
    1/1

    PHP中文网