30 Star 238 Fork 87

店滴云物联网开源框架 / ddiot-茶室民宿酒店棋牌室管理系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
model.md 1.32 KB
一键复制 编辑 原始数据 按行查看 历史

模型

集成模型类

集成模型类需要继承`\common\components\ActiveRecord`类

定义主键

主键默认为`id`,如果主键不是`id`,需要通过`@Property(isPrimaryKey: true)`注解指定主键

定义字段

严格模式需要在模型类中定义字段,非严格模式兼容了yii的rules,rules中的字段必须与会作为私有属性输出

字段默认为`id`,如果字段不是`id`,需要通过`@Property`注解指定字段

输出数组

asArray() : 输出rules中定义的字段

$user = DdUser::findRecord(['mobile'=> $mobile])->asArray();

toArray() : 输出私有属性定义的字段

$user = DdUser::findRecord(['mobile'=> $mobile])->toArray();

代码示例

<?php

namespace addons\diandi_hotel\models\Rpc;



use EasySwoole\FastDb\Attributes\Property;

class ceshiRpcModel extends \common\components\ActiveRecord
{
    #[Property(isPrimaryKey: true)]
    public int $id;
    
    #[Property]
    public ?int $store_id;

    #[Property]
    public ?int $bloc_id;

    /**
     * {@inheritdoc}
     */
    public static function tableName(): string
    {
        return '{{%diandi_switch_ceshi}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules(): array
    {
        return [
            [[
                'bloc_id',
                'store_id',
            ], 'integer'],
            [['create_time', 'update_time'], 'safe']
        ];
    }
}
PHP
1
https://gitee.com/wayfirer/ddiot.git
git@gitee.com:wayfirer/ddiot.git
wayfirer
ddiot
ddiot-茶室民宿酒店棋牌室管理系统
main

搜索帮助