CI $this->load->view不能循环调用

WBOY
Release: 2016-06-23 13:41:46
Original
743 people have browsed it

项目中遇到的一点问题,获取视图的模板并存入数据库,简单描述一下:
1、查询出id
2、循环调用视图

3、create_static_temp_page这个方法会调用视图,取出视图的内容,并将内容存入数据库


问题:
数据库查询到的id明显是多个,循环调用这个方法,经过测试,程序每次运行到$this->db->view这一步就“停止”了,这里停止并不是return或者exit,因为能把视图的内容存入数据库,但是只循环一次,因为我在循环里打印$r['id']只输出一次。

网上找到的一点思路:CI 的视图类$this->db->view会在调用完毕后,运行ob_end_flush(),但这跟循环一次有什么关系?

寻求各位的帮助


回复讨论(解决方案)

看起来逻辑上没有问题。只能一步步调试了。
你看看$arr里有几个元素?

$arr 是一个二维数组
array (size=2)
  0 => 
    array (size=1)
      'id' => string '88' (length=2)
  1 => 
    array (size=1)
      'id' => string '89' (length=2)

我没有好办法了,只能一步步跟踪,看看什么时候停止了,为什么停止了。
对了,记得打开错误信息,可能是出错了,导致程序中止了。

自己调试一下,看你的视图做了什么。

 CI的load view方法使用ob缓存的方法将内容输出到屏幕,$thi->load->view('',true)的第二个参数决定了是否是否使用ob,每次在调用完之后都会执行ob_end_clean(),需要循环调用load view方法的你可以自己再思考思考,主要是ob缓存的一些问题

第三个参数。。。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!