14
Jul
在CodeIgniter如何把控制器的数组传给视图?
我有一个遍历数据库返回的需求,代码如下
//此处获取的值是一个数组 $this->load->database(); $query = $this->db->query("select ID,title from jscodebox where author='jean'"); if ($query->num_rows>0){ $data['filelist'] = $query; } $this->load->view('box',$data); //现在我把这个数组在视图里显示。这里需要注意的是在CodeIgniter中遍历数据库的动作 <ul id="mycodelist" style="list-style-type:none;"> <?php foreach($filelist->result() as $item):?> <li><?php echo $item->title;?></li> <?php endforeach;?> </ul> |