Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yuenblue
PhpDemo
提交
696edeed
P
PhpDemo
项目概览
yuenblue
/
PhpDemo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PhpDemo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
696edeed
编写于
4月 05, 2024
作者:
Y
yuenblue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aaa
上级
d9811a91
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
4 deletion
+49
-4
demotp6/app/model/User.php
demotp6/app/model/User.php
+6
-2
demotp6/config/database.php
demotp6/config/database.php
+2
-2
demotp6/tests/ModelTest.php
demotp6/tests/ModelTest.php
+41
-0
未找到文件。
demotp6/app/model/User.php
浏览文件 @
696edeed
<?php
declare
(
strict_types
=
1
);
namespace
app\model
;
use
stdClass
;
use
think\Model
;
enum
UserState
:
int
{
case
Inactive
=
0
;
...
...
@@ -15,8 +17,10 @@ enum UserState:int{
}
}
/**
* @property int aaa
* @property
* @property string username
* @property string password
* @property string email
* @property int status
*/
final
class
User
extends
Model
{
...
...
demotp6/config/database.php
浏览文件 @
696edeed
...
...
@@ -10,13 +10,13 @@ return [
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp'
=>
true
,
'auto_timestamp'
=>
'datetime'
,
// 时间字段取出后的默认时间格式
'datetime_format'
=>
'Y-m-d H:i:s'
,
// 时间字段配置 配置格式:create_time,update_time
'datetime_field'
=>
''
,
'datetime_field'
=>
'
create_at,update_at
'
,
// 数据库连接配置信息
'connections'
=>
[
...
...
demotp6/tests/ModelTest.php
浏览文件 @
696edeed
<?php
use
app\model\User
;
use
app\model\UserState
;
use
PHPUnit\Framework\TestCase
;
use
think\App
;
...
...
@@ -20,6 +21,46 @@ class ModelTest extends TestCase{
function
testEcho
()
{
$user
=
new
User
();
$user
->
username
=
'aaa'
;
$user
->
email
=
"cccc"
;
$user
->
password
=
'bbbb'
;
$user
->
status
=
UserState
::
Inactive
->
value
;
$user
->
save
();
}
function
testSelect
()
{
// $list=User::select();
// $list = User::order('id','asc')->select([1,2]);
// $list->hidden(['password'])
// ->append(['status_text'])
// ->withAttr('name', function($value, $data) {
// return strtolower($value);
// });
// $list = User::select([1,2]);
$list
=
User
::
where
(
'id'
,
'>'
,
0
)
->
select
()
->
where
(
'username'
,
'aaaa'
)
->
where
(
'status'
,
'>='
,
0
);
// dump($list);
$list
->
update
([
'status'
=>
UserState
::
Activated
->
value
]);
foreach
(
$list
as
$item
)
{
// print $item->username,"\r\n";
echo
$item
->
password
,
PHP_EOL
;
}
}
function
testFind
()
{
$user
=
User
::
where
(
'status'
,
'>='
,
'0'
)
->
find
();
// var_dump($user);
$user
->
password
=
'fff'
;
// $user->create_at=(new DateTime())->format("Y-m-d H:i:s.u");
$user
->
isAutoWriteTimestamp
(
false
)
->
save
();
// \org\util\DateTime
}
function
testDateTime
()
{
// print microtime();
$dt
=
new
DateTime
();
$res
=
$dt
->
format
(
"Y-m-d H:i:s.u"
);
print
$res
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录