Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yuenblue
PhpDemo
提交
15453dbc
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,发现更多精彩内容 >>
提交
15453dbc
编写于
4月 07, 2024
作者:
Y
yuenblue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
aaa
上级
21828e8b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
111 addition
and
5 deletion
+111
-5
README.md
README.md
+3
-1
demotp6/app/model/Article.php
demotp6/app/model/Article.php
+10
-1
demotp6/app/model/ArticleContent.php
demotp6/app/model/ArticleContent.php
+19
-0
demotp6/app/model/User.php
demotp6/app/model/User.php
+5
-0
demotp6/tests/ModelTest.php
demotp6/tests/ModelTest.php
+74
-3
未找到文件。
README.md
浏览文件 @
15453dbc
## 环境变量
## 环境变量
XDEBUG_CONFIG="idekey=VSCODE"
XDEBUG_CONFIG="idekey=VSCODE"
XDEBUG=vscode
XDEBUG=vscode
## 快捷键
ctrl/command + shift + k //删除当前行
## cli
## cli
php think run
php think run
php think make:model
composer create-project topthink/think=~6.0 demotp6
composer create-project topthink/think=~6.0 demotp6
composer create-project topthink/think=~8.0 demotp8
composer create-project topthink/think=~8.0 demotp8
composer create-project topthink/think=~5 demotp5
composer create-project topthink/think=~5 demotp5
...
...
demotp6/app/model/Article.php
浏览文件 @
15453dbc
...
@@ -7,8 +7,17 @@ use think\Model;
...
@@ -7,8 +7,17 @@ use think\Model;
/**
/**
* @mixin \think\Model
* @mixin \think\Model
* @property string $title
*/
*/
class
Article
extends
Model
class
Article
extends
Model
{
{
//
public
const
Content
=
'content'
;
public
function
content
()
{
return
$this
->
hasOne
(
ArticleContent
::
class
);
}
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
);
}
}
}
demotp6/app/model/ArticleContent.php
0 → 100644
浏览文件 @
15453dbc
<?php
declare
(
strict_types
=
1
);
namespace
app\model
;
use
think\Model
;
/**
* @mixin \think\Model
* @property string $content
*/
class
ArticleContent
extends
Model
{
protected
$name
=
'articlecontent'
;
public
function
article
()
{
return
$this
->
belongsTo
(
Article
::
class
)
->
bind
([
"aaa"
=>
'content'
]);
}
}
demotp6/app/model/User.php
浏览文件 @
15453dbc
...
@@ -24,5 +24,10 @@ enum UserState:int{
...
@@ -24,5 +24,10 @@ enum UserState:int{
*/
*/
final
class
User
extends
Model
final
class
User
extends
Model
{
{
public
const
Articles
=
'articles'
;
public
function
articles
()
{
return
$this
->
hasMany
(
Article
::
class
);
}
}
}
demotp6/tests/ModelTest.php
浏览文件 @
15453dbc
<?php
<?php
use
app\model\Article
;
use
app\model\ArticleContent
;
use
app\model\User
;
use
app\model\User
;
use
app\model\UserState
;
use
app\model\UserState
;
use
PHPUnit\Framework\TestCase
;
use
PHPUnit\Framework\TestCase
;
...
@@ -19,15 +21,85 @@ class ModelTest extends TestCase
...
@@ -19,15 +21,85 @@ class ModelTest extends TestCase
{
{
assertTrue
(
true
);
assertTrue
(
true
);
}
}
public
function
testArticleContentBelongsTo
(){
$cc
=
ArticleContent
::
find
(
3
);
print
$cc
->
article
;
}
public
function
testhasMany
()
{
// $uu = User::find(13);
// foreach ($uu->articles()->where("title","aaaaa")->select() as $item) {
// echo $item->title,PHP_EOL;
// }
// print $uu->articles;
// $user=new User();
// $user->username='aaaa';
// $user->save();
// $aa=new Article();
// $aa->title="aaaaa";
// $bb=new Article();
// $bb->title='bbbbb';
// $user->articles()->saveAll([$aa,$bb]);
$wh
=
Article
::
where
(
'user_id'
,
'>'
,
0
);
$uu
=
User
::
with
([
User
::
Articles
])
->
hasWhere
(
User
::
Articles
,
$wh
)
->
select
();
print
$uu
;
}
public
function
testArticleContent
()
{
$aa
=
Article
::
find
(
3
);
$cc
=
new
ArticleContent
();
$cc
->
content
=
'aaaaa'
;
// $aa->content->content="cccccc";
// $aa->content->save();
// $aa->save();
// $cc->save();
$aa
->
content
()
->
save
(
$cc
);
// $aa->save();
}
public
function
testArticle
()
{
// $aaa=Article::withJoin("content")->select();
// foreach ($aaa as $item) {
// print $item;
// }
// $aa=new Article();
// $aa->title="bbb";
// $aa->save();
$aa
=
Article
::
with
(
"content"
)
->
find
(
3
);
$aa
->
content
->
delete
();
$aa
->
delete
();
// print $aa->content->content;
// $aa->content->content = 'cccc';
// $aa->content->save();
// echo $aa->aaa,"???";
// print $aa->content;
}
public
function
testCreateArticle
()
{
$aa
=
new
Article
();
$aa
->
title
=
"ccc"
;
$cc
=
new
ArticleContent
();
$cc
->
content
=
'vvvvvv'
;
$aa
->
content
=
$cc
;
$aa
->
together
([
'content'
])
->
save
();
// $aa->save();
}
public
function
testByName
()
public
function
testByName
()
{
{
$user
=
User
::
getByUsername
(
'aaa'
);
$user
=
User
::
getByUsername
(
'aaa'
);
print
$user
;
print
$user
;
}
}
function
testValueColumn
()
function
testValueColumn
()
{
{
// $res=User::where("id",">",0)->value("email");
// $res=User::where("id",">",0)->value("email");
$res
=
User
::
where
(
"id"
,
">"
,
0
)
->
column
(
"username"
);
$res
=
User
::
where
(
"id"
,
">"
,
0
)
->
column
(
"username"
);
print
$res
;
print
$res
;
}
}
function
testCreate
()
function
testCreate
()
...
@@ -38,7 +110,6 @@ class ModelTest extends TestCase
...
@@ -38,7 +110,6 @@ class ModelTest extends TestCase
$user
->
password
=
'wqsqwsqsw'
;
$user
->
password
=
'wqsqwsqsw'
;
$user
->
status
=
UserState
::
Inactive
->
value
;
$user
->
status
=
UserState
::
Inactive
->
value
;
$user
->
save
();
$user
->
save
();
}
}
function
testSelect
()
function
testSelect
()
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录