zhoupenghui

zhoupenghui

这家伙有点懒,还没写个性签名!

  • 财富值870
  • 威望值120
  • 总积分2510

个人信息

  • 回复了 的回答

    你看看这样行不行:

    $goods= new Goods();
    $attr=['name'=>'西门子','price'=>12,'brand'=>'TOTO'];
    $goods->setAttributes($attr);
    $goods->save();
    

    那个save()方法就可以判断是更新还是添加:

        public function save($runValidation = true, $attributeNames = null)
        {
            if ($this->getIsNewRecord()) {
                return $this->insert($runValidation, $attributeNames);
            } else {
                return $this->update($runValidation, $attributeNames) !== false;
            }
        }
    

    这是源码里的save方法,你可以去看一下文档

  • 回复了 的回答

    这样写,你看行不行?

    UserComment::deleteAll([
    'and',
    ['in','id', $id_list]
    ]);
    

    $id_list里面是数组

    那把and去掉吧,毕竟我也没有测试,不知道行不行哈

  • 可以这样:

    var $username='张三';
    var $email ='qq@qq.com';
    var $mobile =18888888888;
    
    $result=User::find()->where([
    'status'=>1,
    ])->andwhere([
    'or',
    ['like','username',$username],
    ['like','email',$email],
    ['like','mobile',$mobile],
    ])->all();
    
  • 你看看这样行不行:

    $goods= new Goods();
    $attr=['name'=>'西门子','price'=>12,'brand'=>'TOTO'];
    $goods->setAttributes($attr);
    $goods->save();
    
  • 在表USER的模型中创建:
    /**

     * relation: get Task.
     * @return Task
     */
    public function getTask ()
    {
        return $this->hasMany(Task::className(), ['task.u_id' => 'id']);
    }
    

    然后:
    $data=USER::find()->with([
    'task'=>function(\yii\db\ActiveQuery $query){
    $query->counn('u_id');
    },
    ])->all();
    你试一下,我没有测试

  • 可以这样:
    先在表ht_user_comm 的模型中增加:

    public function getHtDiary()
    {
        return $this->hasMany(HtDiary::className(), ['id' => 'cid']);  // hasMany可能为hasOne
    }
    

    ,然后:
    $data = UserComm::find()->with([
    'htDiary'=>function(\yii\db\ActiveQuery $query) use $id{

    $query->where[
    

    'htDiary.id' => $id'
    ]},
    ])->orderBy([
    'user_comm.count_praise' => SORT_DESC
    ])->asArray()->all();
    我没有测试,你试一下

  • 上传时,先用js判断一下图片类型,再在模型中判断类型.模型中增加验证规则:
    public function rules()

    {
        $conf = Yii::$app->params['ware.comment']['image'];
        return array_merge(parent::rules(), [
            [
                'pic', 'image',
                'extensions' => 'jpg, png',
                'mimeTypes' => 'image/jpeg, image/png',
                'minSize' => 1000 * $conf['weight.limit'][0],
                'maxSize' => 1000 * $conf['weight.limit'][1],
                'tooSmall' => '{attribute}不能小于' . $conf['weight.limit'][0] . 'KB',
                'tooBig' => '{attribute}不能大于' . $conf['weight.limit'][1] . 'KB',
                'minWidth' => $conf['size.limit']['min'][0],
                'minHeight' => $conf['size.limit']['min'][1],
            ],
        ]);
    }
    
  • 这样写,你看行不行?

    UserComment::deleteAll([
    'and',
    ['in','id', $id_list]
    ]);
    

    $id_list里面是数组

  • 2016-04-29 已签到
    连续签到1天,获得了5个金钱
总监 等级规则
2510/5000
资料完整度
10/100
用户活跃度
0/100

Ta的关注

2

Ta的粉丝

3

Ta的访客

11