我想学习codeigniter(下面的书),但不明白为什么网页出来空。codeigniter新手问题
我控制器
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$data['title'] = "Welcome to Claudia's Kids";
$data['navlist'] = $this->MCats->getCategoriesNav();
$data['mainf'] = $this->MProducts->getMainFeature();
$skip = $data['mainf']['id'];
$data['sidef'] = $this->MProducts->getRandomProducts(3, $skip);
$data['main'] = "home";
$this->load->vars($data);
$this->load->view('template');
}
的观点是:
<--doctype declaration etc etc.. -->
</head>
<body>
<div id="wrapper">
<div id="header">
<?php $this->load->view('header');?>
</div>
<div id='nav'>
<?php $this->load->view('navigation');?>
</div>
<div id="main">
<?php $this->load->view($main);?>
</div>
<div id="footer">
<?php $this->load->view('footer');?>
</div>
</div>
</body>
</html>
现在我知道该模型是经过重新回到正确的变数,但页面出现完全空白。我希望至少看到一个错误,或基本的HTML结构,但页面只是空的。此外,即使我修改它,控制器也不起作用,如下所示:
function index()
{
echo "hello.";
}
我在做什么错? 一切工作,直到我对模型做了一些更改 - 但即使我删除所有这些新的更改,页面仍然是空白..我真的很困惑!
感谢, P.
我隔绝,让我的问题的功能。 那就是:
function getMainFeature()
{
$data = array();
$this->db->select("id, name, shortdesc, image");
$this->db->where("featured", "true");
$this->db->where("status", "active");
$this->db->orderby("rand()");
$this->db->limit(1);
$Q = $this->db->get("products");
if ($Q->num_rows() > 0)
{
foreach($Q->result_arry() as $row)
{
$data = array(
"id" => $row['id'],
"name" => $row['name'],
"shortdesc" => $row['shortdesc'],
"image" => $row['image']
);
}
}
$Q->free_result();
return $data;
}
我很确信,必须有一个语法错误的地方 - 但仍然不明白为什么它不显示任何错误,即使我已经设置了使用error_reporting E_ALL在索引函数..
Q-> result_arry() - right是result_array()。 (或者它只是一个错字?) – DCrystal 2010-03-19 01:44:00
well spotted :)这是代码中的一个实际错误,但是我已经发现它自己并没有解决问题.. – Patrick 2010-03-20 12:21:07
如果你已经孤立到一个模型中的函数不要发布,所以我们可能会发现错误。 – Eric 2010-03-19 02:55:09