|
本帖最后由 garygay 于 2009-10-29 23:27 编辑
MODEL
- function category(){
- $query = $this->db->query("SELECT * FROM category");
- return $query->result();
- }
复制代码 Controller
- function getcategory(){
- $this->load->Model('Newsmodel');
- $data['category']=$this->Newsmodel->category();
- $this->load->view('header',$data);
- }
复制代码 view
- <ul>
- <?foreach($category as $row):?>
- <li><?=$row->name?></li>
- <?endforeach;?>
- </ul>
复制代码 浏览后,显示A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/header.php
Line Number: 9
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/header.php
Line Number: 9
应该是无法把值传到view里面了,那么究竟错在哪里呢?如何调试? |
|