qingchen

qingchen

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

  • 财富值4270
  • 威望值60
  • 总积分5220

个人信息

  • 2018-07-26 已签到
    连续签到11天,获得了20个金钱
  • 回复了 的评论

    没看明白为什么写这么多
    例:轮播图模型
    Focus.php
    Focus 中 type=0 PC端,type=1 手机端

    FocusQuery.php 中添加方法

    //改自andWhere方法
    public function pc(){
            if ($this->where === null) {
                $this->where = ['type'=>0];
            } elseif (is_array($this->where) && isset($this->where[0]) && strcasecmp($this->where[0], 'and') === 0) {
                $this->where[] = ['type'=>0];
            } else {
                $this->where = ['and', $this->where,['type'=>0]];
            }
            return $this;
        }
    

    Focus.php 添加方法

     public static function pc(){
      return self::find()->pc();
     }
    

    同样能实现

    Focus::find()->pc()->all();
    Focus::pc()->all();
    


    实际用过,能正常返回结果,没发现有什么问题
    想了想
    if可以去掉
    FocusQuery.php 中的函数可以改成

    public function pc(){
        return $this->andWhere(['type'=>0]);
    }
    
  • 没看明白为什么写这么多
    例:轮播图模型
    Focus.php
    Focus 中 type=0 PC端,type=1 手机端

    FocusQuery.php 中添加方法

    //改自andWhere方法
    public function pc(){
            if ($this->where === null) {
                $this->where = ['type'=>0];
            } elseif (is_array($this->where) && isset($this->where[0]) && strcasecmp($this->where[0], 'and') === 0) {
                $this->where[] = ['type'=>0];
            } else {
                $this->where = ['and', $this->where,['type'=>0]];
            }
            return $this;
        }
    

    Focus.php 添加方法

     public static function pc(){
      return self::find()->pc();
     }
    

    同样能实现

    Focus::find()->pc()->all();
    Focus::pc()->all();
    
  • 2018-07-25 已签到
    连续签到10天,获得了20个金钱
  • 赞了回答

    catch (Exception $e)
    改成
    catch (\Exception $e)
    即可

    因为\Exception 是yii所有异常的基类。而你写的Exception可能是上文use的某个命名空间的Exception。然而这个Exception和getBank方法里抛出的异常,不是同一个异常类。所以捕获不到。

    参见:https://taoliujun.github.io/2017/yii-can-not-catch-exception/

  • 2018-07-24 已签到
    连续签到9天,获得了20个金钱
  • 2018-07-22 已签到
    连续签到7天,获得了20个金钱
  • 2018-07-23 已签到
    连续签到8天,获得了20个金钱
  • 2018-07-21 已签到
    连续签到6天,获得了20个金钱
  • 2018-07-20 已签到
    连续签到5天,获得了20个金钱
副总裁 等级规则
5220/10000
资料完整度
20/100
用户活跃度
0/100

Ta的关注

0

Ta的粉丝

5

Ta的访客

20