[TOC]
## 开始开发
#### 路由设置
在/config/domains.php中加入
```
// DEMO示例
'demo' => [
'tpl' => 'www/demo',
'conn' => 'demo',
'icon' => 'static/favicon.ico',
// title: html代码中一定要存在head标签,否则title无效
'title' => 'TPHP框架 - 快速开发'
],
```
- 模板所在路径:/html/www/demo
- 目录不限制层数
- 默认页面路径:/html/www/demo/index
- conn:数据库默认连接设置,在/config/database.php的connections选项中添加如下配置
```
'demo' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'database',
'username' => 'username',
'password' => '******',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'strict' => false,
'engine' => null,
],
```
#### Nginx配置
```
server {
listen 80;
server_name demo.tphp.com admin.demo.tphp.com;
index index.php;
location / {
root 'D:/www/tphp/public/';
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
set $thisuri "$fastcgi_script_name";
set $root_path "D:/www/tphp/public/";
root $root_path;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $root_path$thisuri;
include fastcgi_params;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
set $flag 0;
}
```
#### Apache配置
```
<VirtualHost *:80>
ServerAdmin webmaster@tphp
DocumentRoot "D:/www/tphp/public"
ServerAlias demo.tphp.com admin.demo.tphp.com
ErrorLog "logs/tphp.com-error.log"
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
CustomLog "logs/tphp.com-access.log" common
</VirtualHost>
```
#### Apache开启.htaccess
```
1、找到apache目录下的httpd.conf文件
2、
<Directory />
AllowOverride none
Require all denied
</Directory>
改为
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Satisfy all
</Directory>
3、去掉注释
LoadModule rewrite_module modules/mod_rewrite.so
```
#### 默认页面开发
创建默认layout布局: /html/www/demo/layout/public/tpl.blade.php
```
<!DOCTYPE html>
@php
// 实际效果: <script src="http://demo.tphp.com/static/jquery/jquery.min.js"></script>
// 插件开发中有详细说明
$plu->js('@static/jquery/jquery.min.js');
@endphp
<html lang="zh-CN">
<head>
</head>
<body>
{!! $__tpl__ !!}
</body>
</html>
```
新建文件:/html/www/demo/index/tpl.blade.php
添加内容:Hello TPHP!
现在就可以访问页面了 [http://demo.tphp.com/](http://demo.tphp.com/)

或者 [http://demo.tphp.com/index](http://demo.tphp.com/index)

查看源码
```
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>TPHP框架 - 快速开发</title>
<script src="http://demo.tphp.com/static/jquery/jquery.min.js"></script>
</head>
<body>
Hello TPHP!
</body>
</html>
```
#### 自定义页面
新建文件:/html/www/demo/test/my/page/tpl.blade.php
添加内容:路由自动指向,创建页面就是这么简单!
访问路径:[http://demo.tphp.com/test/my/page](http://demo.tphp.com/test/my/page)

也可以这样:[http://demo.tphp.com/test/my/page.html](http://demo.tphp.com/test/my/page.html)

- 路由是随便定义的,级数不受限制。
- 目录就是模块,这里用的是模块中的HTML方式。
## 路由扩展配置
在对应的根目录创建data.php文件: /html/www/demo/data.php
```
<?php
// 同routes配置的top效果一样
/*
Route::get('top', function(){
return "山穷水尽疑无路,柳暗花明又一村。";
});
*/
// 该配置优先级高于domains.php,但参数 'tpl' => 'www/demo' 不会生效。
return [
'routes' => [
'get' => [
'top' => function(){
return "山穷水尽疑无路,柳暗花明又一村。";
}
]
]
];
```
打开网址[http://demo.tphp.com/top](http://demo.tphp.com/top)获得如下效果

- 这样就不会使得domains.php配置过多而导致设置混乱,特别是在项目多的情况下。