安裝:
composer create-project topthink/think project-name
更新:
composer update topthink/framework
其他
目錄結構: http://localhost/project-name/public/index.php
url 訪問地址: http://serverName/index.php/控制器/操作/參數/值...
控制器文件位置: app\controller\Index.php
訪問 URL 地址是(沒有定義路由的情況下):http://serverName/index.php/index/hello/name/phpzhi
路由定義:(Route::rule('路由表達式‘, ’路由地址‘,’請求類型‘)
Route::get('hello/:name', 'index/hello');
//訪問 http://abc.com/hello/123,訪問的是 Index 控制器下的 hello 方法,參數123
模板渲染:
View::assign('name', 'phpzhi');
return View::fetch('index');
助手函數:
return \view('index', [
'name' => 'phpzhi',
'email' => '[email protected]'
]);
不存在的控制器和操作只要view下有目錄一樣能渲染:
return View::fetch('public/menu');
環境變量定義並讀取配置:(在應用根目錄下定義一個文件 .env,默認文件爲 .example.env)
// .env 文件內容
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
獲取環境變量的值,use think\facade\Env;
,如果 .env
裏不存在username,則使用 root,echo Env::get('database.username', 'root');
文件定義並讀取配置內容:(文件目錄是在根目錄的 config/ 下),use think\facade\Config;
,讀取 route.php 配置文件下的 url_html_suffix 值 echo Config::get('route.url_html_suffix');