前提:首先要了解下如何自建composer包。
1.先建一个空包,加一个文件:composer.json
{
"name": "test/ctrs",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"app\\controller\\ctrs\\": "src/"
}
}
}
2.建一个源码目录src,在src下建相关文件:
Test.php
<?php
namespace app\controller\ctrs;
use think\facade\View;
class Test
{
public function index()
{
// 设置视图目录
View::config(['view_path' => __DIR__ . '/view/']);
// View::config(['view_path' => 'D:\tmp\test\php\2\tp\vendor\test\ctrs\src\view/']);
return view('index', array('time' => time()));
}
}
布局文件:layout.html
<!DOCTYPE html>
<html>
<head>
<title>{block name="title"}默认标题{/block}</title>
</head>
<body>
<h1>layout!!</h1>
{block name="body"}body{/block}
</body>
</html>
视图文件:
{extend name="layout" /}
{block name="title"}
页面标题
{/block}
{block name="body"}
<h2>Composer 包中的视图!!</h2>
<div>
time:{$time}
</div>
{/block}