本帖最后由 小凡 于 2010-10-17 21:38 编辑
首先说下我的控制器里面的代码:
<?php
class Blog extends Controller{
function Blog()
{
parent::Controller();
}
function index()
{
$this->load->model('Blogmodel','',TRUE);
$data['query'] = $this->Blogmodel->get_last_ten_entries();
$this->load->view("blogview",$data);
}
}
?>
接下来是我的model里面的代码:
class Blogmodel extends Model {
function Blogmodel()
{
parent::Model();
}
function get_last_ten_entries()
{
$query = $this->db->get('news', 10);
return $query->result();
}
}
?>
最后贴出我的试图下的代码:这个视图的代码应该有错误,但是我不会该
<!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=gb2312" />
<title></title>
</head>
<body>
<ul>
<?php foreach($query as $item): ?>
<li><?php
if(is_array($item)):
foreach($item as $val): echo $val;
endforeach;
else:
echo $item;
endif;
?>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
下面是错误提示:
A PHP Error was encountered
Severity: 4096
Message: Object of class stdClass could not be converted to string
Filename: views/blogview.php
Line Number: 12
错误意思大概是是 类的对象不能改造成字符串吧 看的不是很懂 小弟今天刚刚接触CI,完全是新生,希望大家能够细心帮助下,谢谢啦!!!
最后把我要查询的数据库贴出来
|