配置文件開啟gii
里面有運行的ip
`YII_ENV_DEV`這個在index.php那要設為true
~~~
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '0.0.0.0']
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
~~~
**自定義gii模板**
以CRUD的模板為例,默認的gii模板位置是在:`<project>/vendor/yiisoft/yii2-gii/generators/crud`的`default`目錄下,我們可以在此新建一個和default同級的目錄,但是并不推薦在這里新建,因為這里是`vendor`目錄。`vendor`目錄下的東西盡量不要去更改,這樣你在`git`發布時或團隊共享時不需要提交`vendor`目錄,比較方便。
推薦的做法是,將`default`文件夾復制出來,移動到我們自定義的位置,我這里移動到了`<project>/backend/views/gii/crud`目錄下,然后更改改`<project>/backend/common/main-local.php`下的`gii`模塊的配置:
~~~
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'generators' => [
'crud' => [
'class' => 'yii\gii\generators\crud\Generator',
templates' => [ //setting for out templates
'curder' => '@backend/views/gii/crud/default', // template name => path to template
]
]
],
];
~~~
經過上面的配置,再訪問`gii`模塊的**CRUD生成器**就會發現多了一個選擇:(如果改的是**backend模塊**的配置,那么只能通過后臺的url訪問gii才會出現多出來的選項,例如:[http://localhost/yii2/advanced/frontend/web/index.php?r=gii)](http://localhost/yii2/advanced/frontend/web/index.php?r=gii%EF%BC%89)
記得要改拷貝過來的內容`<project>/backend/views/gii/crud/default/views`下的文件可以進行修改,例如刪除掉多出來的標題什么的,然后重新生成一遍,就可以看到改變后的效果了。
以后生成一些通用CRUD代碼就可以使用這個模板進行生成了。
- 目錄
- 配置
- 簡介
- 別名
- gii
- 配置項
- 模型
- 簡介
- 增刪改查
- AR和model
- 模型事件
- 場景
- query查詢
- 增刪改
- AR查詢器
- 模型關系定義
- AR模型連表查詢
- fields
- where拼接
- 模塊
- 創建模塊
- 控制器
- 表單
- 跳轉
- 響應
- 驗證器
- Action
- 組件
- url
- 分頁
- 驗證碼
- 緩存
- 文件上傳
- 預啟動組件
- 事件
- 自定義組件
- redis
- 日志
- 行為
- cookie和session
- 基礎知識
- 創建一個類
- 配置一個類
- object基類
- component組件類特性
- phpstorm無法更改php等級
- url地址美化
- 過濾器
- 請求處理
- 請求組件
- 響應組件
- header
- 用戶登錄
- 實現IdentityInterface接口
- 登錄
- 自動檢測登錄
- 獲取用戶信息
- 訪問行為追蹤
- phpstorm+postman斷點調試