# 升级说明
>
> + [5.0.X升级到5.1官方说明](https://www.kancloud.cn/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]如下,与之前版本有所区别
~~~
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
';
}
-----
}
~~~
### 3.2模板输出区别【默认进行html过滤】
>[info]模板输出html代码需要特别注意,默认系统对html进行了过滤
~~~
.....
class Index extends Controller
{
public function index()
{
$html = '
hi
';$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);
~~~