[TOC] ## 开始开发 #### 路由设置 在/config/domains.php中加入 ~~~ //DEMO示例 'demo' => [ 'tpl' => 'www/demo', 'conn' => 'demo', '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> ``` #### 默认页面开发 新建文件:/html/www/demo/index/tpl.blade.php 添加内容:Hello Tphp! 现在就可以访问页面了 [http://demo.tphp.com/](http://demo.tphp.com/) ![](https://img.kancloud.cn/10/9e/109ec10a8a3a48965d000fe078d74bed_357x152.png) 或者 [http://demo.tphp.com/index](http://demo.tphp.com/index) ![](https://img.kancloud.cn/0e/1e/0e1e477c4d45d65b9af7be4a390d3c70_389x136.png) #### 自定义页面 新建文件:/html/www/demo/test/my/page/tpl.blade.php 添加内容:路由自动指向,创建页面就是这么简单! 访问路径:[http://demo.tphp.com/test/my/page](http://demo.tphp.com/test/my/page) ![](https://img.kancloud.cn/9d/87/9d87c6bb885f9477c0f8d0584d88dca3_442x154.png) 也可以这样:[http://demo.tphp.com/test/my/page.html](http://demo.tphp.com/test/my/page.html) ![](https://img.kancloud.cn/60/bd/60bd48cdd25738332d8f220ae5ca6cdd_458x137.png) - 路由是随便定义的,级数不受限制。 - 目录就是模块,这里用的是模块中的HTML方式。