|
发表于 2012-7-23 18:58:56
|
显示全部楼层
Mhome.php(模型)
<?php
class Mhome extends Model{
function __construct()
{
parent::Model();
}
function get_category()
{
$query = $this->db->query('select * from category');
return $query->result();
}
}
home.php(控制器)
<?php
class Home extends Controller{
function __construct()
{
parent::Controller();
}
function index()
{
$this->load->model('Mhome');
$date['category'] = $this->Mhome->get_category();
$date['page_title'] = 'ci开发新闻发布系统';
$this->load->view('header',$date);
$this->load->view('index');
$this->load->view('footer');
}
}
header.php(头部文件 )
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$page_title?></title>
<?foreach ($category as $row):?> 注:这里想循环输出category_name
<?=$row->category_name?>
<?endforeach;?>
</html>
一运行就出现这种错误提示:
A PHP Error was encounteredSeverity: Notice
Message: Undefined variable: category
Filename: views/header.php
Line Number: 6
A PHP Error was encounteredSeverity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/header.php
Line Number: 6
那位大哥能解说一下 先谢拉
|
-
-
|