1、在文件夹usr/ctrl/h3下新建控制器Home.php
<?php namespace Ctrl\H3;//一定要指定在该命名空间下,否则路由会失败 use Lib;//使用控制器基类必须声明使用该命名空间 class Home extends Lib\CtrlBase { function Index() { $this->set("say","hello word!!"); return $this->view(); } } ?>
说明:
$this->set("say","hello word!!");赋值模板变量的语句
注意以下2个语句是等价的
return $this->view(); //view方法没有传递参数时,效果等同下面这句
return $this->view('Index'); //渲染usr/tpl/default/Index.htm模板
view()方法还有更多功能,比如指定特定的布局母版或指定不使用母版
2、在usr/tpl/h3/home 下新建模板文件 Index.htm
输入内容:
<h2>{$say},H3</h2>
3、现在可以在浏览器输入 http://localhost/h3/home/index 查看效果了