沃斯尼达耶

沃斯尼达耶

清华落榜生

  • 财富值2065
  • 威望值0
  • 总积分2405

个人信息

  • 发表了说说
    大佬们 关注一下问题
  • 用了这个方法

    public function attributes ()
    {
        $attributes = parent::attributes();
        $attributes[] = 'count';
        $attributes[] = 'name';
        return $attributes;
    }
    

    是多了两个属性 但是查询出来的结果 还是没有他俩, 是需要在哪里给这俩赋值么?

    $attributes = 
    Array
    (
        [0] => id
        [1] => uid
        [2] => from_uid
        [3] => type
        [4] => amount
        [5] => ori_amount
        [6] => created_at
        [7] => totals
        [8] => is_incr
        [9] => remark
        [10] => sent
        [11] => sent_time
        [12] => count
        [13] => name
    )
    
  • AR是啥意思啊?

    ActiveRecord

  • 回复了 的回答
    // Yii2 active_record 添加额外属性
    public function attributes()
    {
        $attributes = parent::attributes();
        $attributes[] = 'type';
        return $attributes;
    }
    

    谢谢, 用了这个办法 还是没有

    public function attributes ()
    {
        $attributes = parent::attributes();
        $attributes[] = 'count';
        $attributes[] = 'name';
        return $attributes;
    }
    
    {"code":200,"error":0,"data":[{"id":"84","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"1194.00","created_at":1553238260,"totals":"1791.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553238260},{"id":"82","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"597.00","created_at":1553238078,"totals":"1194.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553238078},{"id":"80","uid":325,"from_uid":327,"type":"rec","amount":"597.00","ori_amount":"0.00","created_at":1553237952,"totals":"597.00","is_incr":1,"remark":null,"sent":1,"sent_time":1553237952}],"message":""}
    
  • 在 AR 里使用 getXX 方法 $model->xx时才有值, 现在就是想查询出来的数据 能加入属性。

  • 还有 比如数据表里是没有 count 属性的, 我怎么才能在每一条查询结果里 加上count属性 并且计算出结果赋值给count属性。

  • 2019-04-09 已签到
    连续签到1天,获得了5个金钱
  • 2019-04-04 已签到
    连续签到1天,获得了5个金钱
  • 2019-03-26 已签到
    连续签到2天,获得了10个金钱
总监 等级规则
2405/5000
资料完整度
40/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

8

Ta的访客

147