ThinkPHP5框架
一、下载tp5框架(composer)
1.安装composer
在windows中,下载并运行Composer-Setup.exe,(安装注意选中php.exe文件,phpstudy环境实在php文件下,之后环境以phpstudy为例)
使用国外的镜像速度会比较慢,
国内镜像:命令行中执行
composer config -g repo.packagist composer https://packagist.phpcomposer.com
2.composer下载tp5框架
进入web根目录(www),命令行执行如下代码:
composer create-project topthink/think=5.0.* tp5 --prefer-dist
当然还有其他的下载方法,个人喜欢用composer,其他就不一一赘述了^_^
二、tp5框架使用中的一些技巧
1、自动生成模块
进入应用的根目录,执行命令行:
> php think build --module test
使用命令行创建controller
进入应用根目录
>php think make:controller 模块/控制器
>php think make:controller test/index
2、路由的写法
application/route.php(路由定义页面)
Route::get('模块','控制器/操作')
Route::get('test','Index/index');
当然不只有get请求,
Route::get('test','Index/index'); // 定义GET请求路由规则
Route::post('test','Index/index'); // 定义POST请求路由规则
Route::put('test','Index/index'); // 定义PUT请求路由规则
Route::delete('test','Index/index'); // 定义DELETE请求路由规则
Route::any('test','Index/index'); // 所有请求都支持的路由规则
3隐藏入口文件
修改public/.htaccess文件
Apache
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
phpstudy
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>
nginx(在nginx/conf/下有vhosts.conf则在这个配置文件中添加,否则在nginx.conf中添加)
location / { // …..省略部分代码
//添加如下代码即可
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?s=/$1 last;
}
}

浙公网安备 33010602011771号