一步一步创建第一个 ThinkPHP5 程序(二)
使用模板
创建 app/hello/controller/Now.php,内容为:
<?php
namespace app\hello\controller;use think\Controller;
class Now extends Controller
{
public function index()
{
$this->assign('now', date('Y-m-d H:i:s'));
return $this->fetch();
}
}
访问 http://localhost/tp5-test01/hello/now , 提示:
template file not exists: .../tp5-test01/app/hello\view\now\index.html
创建 app/hello/view/now/index.html,内容为:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>当前时间</title>
</head>
<body>
当前时间是 {$now}。
</body>
</html>
访问 http://localhost/tp5-test01/hello/now , 应该处理一个显示当前时间的页面。
全文:http://blog.sina.com.cn/s/blog_6262a50e0102ws6u.html

浙公网安备 33010602011771号