Skip to content

Commit f093c29

Browse files
committed
优化模型类
1 parent 01b62dd commit f093c29

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

.env

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[app]
2+
23
debug = true
34

45
[database]
5-
host => 127.0.0.1, //一般不需要修改
6-
port => 3306, //默认即可
7-
dbuser => root, //数据库用户名
8-
dbpwd => 123456, //数据库密码
9-
dbname => linkphp, //数据库名称
10-
dbprefix => lp_, //数据库表前缀
6+
7+
host = 127.0.0.1
8+
port = 3306
9+
dbuser = root
10+
dbpwd = 123456
11+
dbname = linkphp
12+
dbprefix = lp_

conf/database.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
'dbname' => Env::get('database.dbname', 'linkphp'), //数据库名称
1212
'dbprefix' => Env::get('database.dbprefix', 'lp_'), //数据库表前缀
1313
'db_type' => 'mysql', //数据库类型 默认Mysql
14+
'result_type' => PDO::FETCH_ASSOC,
15+
// 时间字段取出后的默认时间格式,默认为Y-m-d H:i:s
16+
'datetime_format' => true,
1417
// Query类
1518
'query' => \linkphp\db\Query::class,
1619
];

src/application/http/controller/Home.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class Home extends Controller
99
public function main()
1010
{
1111
$model = new HomeModel();
12-
dump($model->select());die;
13-
return ['code' => 200, 'msg' => 'linkphp 创建成功!'];
12+
return ['code' => 200, 'msg' => $model->find()->toArray()];
1413
}
1514

1615
}

src/application/http/model/Home.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
class Home extends Model
88
{
99

10+
protected $field = ['id'];
11+
1012
protected $name = 'forum';
1113

14+
protected $updateTime = 'post_time';
15+
16+
protected $createTime = 'up_time';
17+
1218
}

src/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
$app->event(
3636
'system',
3737
[
38+
\linkphp\event\provider\EnvProvider::class,
3839
\linkphp\event\provider\ConfigProvider::class,
3940
\linkphp\event\provider\MiddleProvider::class,
4041
\linkphp\event\provider\DatabaseProvider::class,

0 commit comments

Comments
 (0)