Skip to content

修改配置数据库方式 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOSTNAME=127.0.0.1
DB_DATABASE=lin_cms
DB_USERNAME=root
DB_PASSWORD=123456
DB_HOSTPORT=3306
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,26 @@ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# 接着执行以下命令安装依赖包
composer install
```
## 复制环境配置文件

```bash
cp .env.example .env
```

## 数据库配置

Lin 需要你自己在 MySQL 中新建一个数据库,名字由你自己决定。例如,新建一个名为 lin-cms 的数据库。接着,我们需要在工程中进行一项简单的配置。使用编辑器打开 Lin 工程根目录下``/config/database.php``,找到如下配置项
Lin 需要你自己在 MySQL 中新建一个数据库,名字由你自己决定。例如,新建一个名为 lin-cms 的数据库。接着,我们需要在工程中进行一项简单的配置。修改.env

```php
// 服务器地址
'hostname' => '',
// 数据库名
'database' => 'lin-cms',
// 用户名
'username' => 'root',
// 密码
'password' => '',

//省略后面一堆的配置项
```
# 服务器名
DB_HOSTNAME=
# 数据库名
DB_DATABASE=lin_cms
# 用户名
DB_USERNAME=
# 密码
DB_PASSWORD=
DB_HOSTPORT=
```

**请务必根据自己的实际情况修改此配置项**
Expand Down Expand Up @@ -218,4 +222,4 @@ QQ 群号:643205479

微信搜索:林间有风

<img class="QR-img" src="http://imglf6.nosdn0.126.net/img/YUdIR2E3ME5weEdlNThuRmI4TFh3UWhiNmladWVoaTlXUXpicEFPa1F6czFNYkdmcWRIbGRRPT0.jpg?imageView&thumbnail=500x0&quality=96&stripmeta=0&type=jpg">
<img class="QR-img" src="http://imglf6.nosdn0.126.net/img/YUdIR2E3ME5weEdlNThuRmI4TFh3UWhiNmladWVoaTlXUXpicEFPa1F6czFNYkdmcWRIbGRRPT0.jpg?imageView&thumbnail=500x0&quality=96&stripmeta=0&type=jpg">
3 changes: 1 addition & 2 deletions application/api/behavior/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Logger
*/
public function run($params)
{

// 行为逻辑
if (empty($params)) {
throw new LoggerException([
Expand All @@ -34,7 +33,7 @@ public function run($params)
}

if (is_array($params)) {
list('uid' => $uid, 'username' => $username, 'msg' => $message) = $params;
list($uid, $username, $message) = $params;
} else {
$uid = Token::getCurrentUID();
$username = Token::getCurrentName();
Expand Down
6 changes: 4 additions & 2 deletions application/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function rand_char($length)
return $str;
}

function split_modules($auths, $key = 'module')
function split_modules($auths, $module = 'module')
{
if (empty($auths)) {
return [];
Expand Down Expand Up @@ -131,7 +131,9 @@ function paginate()

$start = $start * $count;

if ($start < 0 || $count < 0) throw new ParameterException();
if ($start < 0 || $count < 0) {
throw new ParameterException();
}

return [$start, $count];
}
10 changes: 5 additions & 5 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => 'localhost',
'hostname' => env('DB_HOSTNAME', 'localhost'),
// 数据库名
'database' => 'lin-test',
'database' => env('DB_DATABASE', 'lin_test'),
// 用户名
'username' => 'root',
'username' => env('DB_USERNAME', 'root'),
// 密码
'password' => '',
'password' => env('DB_PASSWORD', ''),
// 端口
'hostport' => '',
'hostport' => env('DB_HOSTPORT', 3306),
// 连接dsn
'dsn' => '',
// 数据库连接参数
Expand Down