首先修改app\crtlindex.php文件内容:
<?php
namespace app\ctrl;
class indexCtrl extends \core\imooc
{
public function index()
{
$temp = new \core\lib\model();
$data = "Hello World";
$title = "这是视图文件";
$this->assign('title',$title);
$this->assign('data',$data);
$this->display("index.html");
}
}
要想渲染视图首先我们要在core\imooc.php中创建俩个方法:
//为视图文件赋值
public function assign($name, $value)
{
$this->assign[$name] = $value;
}
//调用视图文件
public function display($file)
{
$file = APP.'/views/'.$file;
if (is_file($file)) {
extract($this->assign);
include $file;
}
}
在app\创建文件夹views和文件index.html:
<h1><?php echo $title ;?></h1>
<h3><?php echo $data ;?></h3>
最后浏览器显示为: