From af55970ee87833cf534d04c7e05284680daffb16 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 20 Apr 2023 22:35:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E5=AE=9E=E4=BE=8B=E5=8C=96?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E4=BB=BB=E6=84=8F=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model.php | 4 ++-- src/model/concern/Attribute.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Model.php b/src/Model.php index 331e797f..78dc59b9 100644 --- a/src/Model.php +++ b/src/Model.php @@ -231,9 +231,9 @@ public function invoke($method, array $vars = []) /** * 架构函数. * - * @param array|Model $data 数据 + * @param array|object $data 数据 */ - public function __construct(array|Model $data = []) + public function __construct(array|object $data = []) { // 设置数据 $this->data($data); diff --git a/src/model/concern/Attribute.php b/src/model/concern/Attribute.php index 35eadb55..0b942323 100644 --- a/src/model/concern/Attribute.php +++ b/src/model/concern/Attribute.php @@ -221,16 +221,18 @@ protected function getRealFieldName(string $name): string /** * 设置数据对象值 * - * @param array|Model $data 数据 + * @param array|object $data 数据 * @param bool $set 是否调用修改器 * @param array $allow 允许的字段名 * * @return $this */ - public function data(array|Model $data, bool $set = false, array $allow = []) + public function data(array|object $data, bool $set = false, array $allow = []) { if ($data instanceof Model) { $data = $data->getData(); + } elseif (is_object($data)) { + $data = get_object_vars($data); } // 清空数据