1.composer 更新命令#composer self-update
2.安裝tp最新版5.0#composer create-project topthink/think=5.0.* tp5 --prefer-dist
001--ThinkPHP5.0-5.1隱藏入口文件 index.php
1,找到/public/.htaccess文件,如果你的入口文件已經移動到根目錄下,那麼你的.htaccess文件也要剪切到根目錄下,總之要確保.htaccess跟入口的index.php保持同級。
2,根據你的php環境分別設置.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>
002--視圖實例化
<?php
namespace app\index\controller;
use think\Controller; //控制器繼承了\think\Controller類的話,則無需自己實例化視圖類,可以直接調用控制器基礎類封裝的相關視圖類的方法。
class Index extends Controller //類也要 extends Controller 才能調用fetch方法去渲染輸出
{
public function index()
{
return 'ThinKPHP5.0';
}
public function hello()
{
return $this->fetch();
}
}
如果你只是需要渲染模板輸出的話,可以使用系統提供的助手函數view
,可以完成相同的功能:
return view('hello',['name'=>'thinkphp']);
助手函數調用格式:
view('[模板文件]'[,'模板變量(數組)'][,模板替換(數組)])
無論你是否繼承think\Controller
類,助手函數都可以使用,也是最方便的一種。
模板
在當前模版文件中包含其他的模版文件使用include標籤,標籤用法:
{include file='模版文件1,模版文件2,...' /}
{:url('控制器/方法')}