我是 PHP 和 CodeIgniter 的新手,目前正在学习两者的教程。我正在尝试构建博客教程,但收到了一些错误。帮助将不胜感激。提前致谢!
控制器:
<?php
class Blog extends Controller{
function index()
{
$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
$data['todo'] = array('clean house','eat lunch','call mom');
$this->load->view('blog_view');
}
}
?>
查看:
<html>
<head>
<title><?=$title?></title>
</head>
<body>
<h1><?=$heading?></h1>
<ol>
<?php foreach($todo as $item): ?>
<li><?=$item?></li>
<?php endforeach; ?>
</ol>
</body>
</html>
错误:
Message: Undefined variable: heading
Filename: views/blog_view.php
Line Number: 6
Message: Undefined variable: todo
Filename: views/blog_view.php
Line Number: 10
Message: Invalid argument supplied for foreach()
Filename: views/blog_view.php
Line Number: 10