# 升級說明
>
> + [5.0.X升級到5.1官方說明](http://www.hmoore.net/manual/thinkphp5_1/354155)
>+ [5.0.X升級到5.1官方說明2](http://www.thinkphp.cn/topic/47882.html)
補充說明
* 獲取數據表信息
\think\Db::getTableinfo('表全名');
## 添加修改post
```
//自動加入字段編輯
protected function changeData()
{
if ($this->request->isPost()){
$post = input('post.');
$post['test_time'] = strtotime(input('post.test_time'));
$post['finish_time'] = strtotime(input('post.finish_time'));
$post['charge_operator_time'] = strtotime(input('post.charge_operator_time'));
$post['charge_customer_time'] = strtotime(input('post.charge_customer_time'));
$this->request->withPost($post);
}
}
```
## 1.入口文件 index.php
>[info]如下,與之前版本有所區別
~~~
<?php
namespace think;
// [ 應用入口文件 ]
// 定義應用目錄
// supper tp5.1
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
define('APP_PATH', __DIR__ . './apps/');
// 加載框架引導文件
require __DIR__ . './thinkphp/base.php';
// 執行應用并響應
Container::get('app', [APP_PATH])->run()->send();
~~~
## 2.配置區別
>[info]所有配置 位于項目
>config目錄下,并區分
>[warning] 注意: 模塊配置文件,集中存放在 項目 根目錄下的 **config** 之中,如下目錄結構
~~~~
www WEB部署目錄(或者子目錄)
├─application 應用目錄
│ ├─common 公共模塊目錄(可以更改)
│ ├─module_name 模塊目錄
│ │ ├─common.php 模塊函數文件
│ │ ├─controller 控制器目錄
│ │ ├─model 模型目錄
│ │ ├─view 視圖目錄
│ │ ├─config 配置目錄
│ │ └─ ... 更多類庫目錄
│ │
│ ├─command.php 命令行定義文件
│ ├─common.php 公共函數文件
│ └─tags.php 應用行為擴展定義文件
│
├─config 應用配置目錄
│ ├─module_name _模塊配置目錄_
│ │ ├─database.php 數據庫配置
│ │ ├─cache 緩存配置
│ │ └─ ...
~~~~
## 3.控制器 controller 注意點
### 3.1初始化方法區別
默認初始化方法名稱變更
5.0.x版本為 **_initialize()** 而5.1為 **initialize()**
>[warning] 注意 少了 **_**
5.1版本 代碼如下
~~~
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function initialize()
{
echo 'init<br/>';
}
-----
}
~~~
### 3.2模板輸出區別【默認進行html過濾】
>[info]模板輸出html代碼需要特別注意,默認系統對html進行了過濾
~~~
.....
class Index extends Controller
{
public function index()
{
$html = '<h1>hi</h1>';
$this->assgin('html',$html);
return $this->fetch();
}
.....
}
要輸出完整的html 在對應模板 index.html 中
{$hmtl |raw}
~~~
>[warning] 調用函數 raw 進行處理,
## 4.原系統常量問題
>[info]5.1版本后,取消了系統常量
* 解決辦法一
> 參考之前版本,自定義
define('XXX','sdfsdf');
* 解決方法二
> 采用tp5.1 版本方法
> 如獲取系統版本信息,
` app()->version() ` 注:之前是 `THINK_VERSION`
Env::get(); 或 app('env')->get()
## 5.系統類實例化區別
> 實例化緩存類方法
* 方法一 類以于以前版本
~~~
use think\facade\Cache;
$cache = new Cache();
~~~
* 方法二 新方法
~~~
//// 注冊容器對象實例
$app = app();
// 判斷對象實例是否存在
isset($app->cache);
$app->cache = think\Cache::class;
// 獲取容器中的對象實例
$cache = $app->cache;
// 快速調用(自動實例化)
$cache = app('cache');
// 每次調用都會重新實例化
$cache = app('cache',true);
~~~
- 文檔說明
- 5.1對比5.0.X版本需要注意點
- 待解答問題QA
- THINKPHP基礎
- 常用技巧
- tp5.1系統信息
- 容器、Facade、依賴注入
- 其它要點記錄
- 數據庫與模型
- 數據集
- AQ問題集
- API開發
- restful開發
- restful測試之ZClient開發
- api開發
- 緩存
- 組件開發
- 采集組件ZSnoopy
- restful測試組件ZClient
- thinkphp各功能模塊
- thinkphp-Log
- 隊列thinkphp-Queue
- THINKPHP擴展
- 單元測試
- 類庫庫遷移工具Migration
- 命令行
- 關于console擴展要點
- 附錄
- 第三方實用PHP庫
- 實用IP庫
- phpQuery庫
- Guzzle庫
- Markdown解釋庫Parsedown
- 上線的項目debug組件
- nette/utils實用函數庫
- 推薦框架DolphinPHP
- Thinkphp之widget
- 表單組件form
- 前端框架推薦
- 推薦框架fastadmin
- PHP7最新語法
- 前端框架
- Echart
- mysql觸發器
- PHP實用技巧與函數
- composer實用筆記