# ThinkPHP6 雜項
---
## `ThinkPHP6` 細節
### 1、創建公用方法
```php
app/common.php 示例:
/**
* 取某天零點時間戳(本地時間)
* @param number $time 欲獲取當日的時間戳
* return number 這天零點時間戳
*/
function getZeroTime($time){
// Z 時差偏移量的秒數。UTC 西邊的時區偏移量總是負的,UTC 東邊的時區偏移量總是正的。
$timezone = date('Z', $time);
$time += $timezone;
$time = $time - $time % 86400 - $timezone;
return $time;
}
```
```php
controller示例:
namespace app\index\controller;
use app\BaseController;
class Index extends BaseController{
public function index(){
$time = getZeroTime('1561785828');
print_r($time.'<br/>');
print_r(date('Y-m-d H:i:s',$time));
}
}
```
### 2、創建共用類方法
```php
BaseController 示例:
/**
* 取某天零點時間戳(本地時間)
* @param number $time 欲獲取當日的時間戳
* return number 這天零點時間戳
*/
public function getZeroTime($time){
// Z 時差偏移量的秒數。UTC 西邊的時區偏移量總是負的,UTC 東邊的時區偏移量總是正的。
$timezone = date('Z', $time);
$time += $timezone;
$time = $time - $time % 86400 - $timezone;
return $time;
}
```
```php
controller示例:
namespace app\index\controller;
use app\BaseController;
class Index extends BaseController{
public function index(){
$time = $this->getZeroTime('1561785828');
print_r($time.'<br/>');
print_r(date('Y-m-d H:i:s',$time));
}
}
```
### 3、事務操作
* 使用事務處理的話,需要數據庫引擎支持事務處理。比如 `MySQL` 的 `MyISAM` 不支持事務處理,需要使用 `InnoDB` 引擎。
```php
namespace app\index\controller;
use app\BaseController;
use think\facade\Db;
class Index extends BaseController{
public function index(){
Db::startTrans();
$delete = Db::table('admin')->delete(1);
if($delete){
Db::commit();
}else{
Db::rollback();
}
}
}
```
- 序言
- PHP基礎
- 認識PHP
- 環境安裝
- PHP語法
- 流程控制
- PHP數組
- PHP函數
- PHP類與對象
- PHP命名空間
- PHP7新特性
- PHP方法庫
- PHP交互
- 前后端交互
- 項目常規開發流程
- MySQL數據庫
- 會話控制
- Ajax分頁技術
- 細說函數
- 類與對象
- 對象進階
- 類與對象進階
- OOP面向對象
- 設計模式
- 路由與模板引擎
- 異常類
- PHP爬蟲
- PHP抓取函數
- PHP匹配函數
- 正則表達式
- PHP字符串函數
- 抓取實戰
- PHP接口
- 了解接口
- PHP插件
- PHPSpreadsheet
- ThinkPHP6
- 安裝
- 架構
- 數據庫
- 數據庫操作
- 視圖
- 模版
- 模型
- 雜項
- 命令行
- 交互
- 微信小程序
- 介紹
- 配置
- 組件
- 交互
- API
- 其他知識
- 百度小程序
- 介紹
- 配置
- 組件
- 交互
- API
- 其他知識
- Linux
- 服務器上線流程
- 安裝svn
- MySQL
- 認識MySQL
- MySQL函數
- 雜項
- composer依賴管理工具