qingchen
- qingchen 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();
- qingchen 2018-07-25 已签到连续签到10天,获得了20个金钱
- qingchen 赞了回答
catch (Exception $e)
改成
catch (\Exception $e)
即可因为\Exception 是yii所有异常的基类。而你写的Exception可能是上文use的某个命名空间的Exception。然而这个Exception和getBank方法里抛出的异常,不是同一个异常类。所以捕获不到。
参见:https://taoliujun.github.io/2017/yii-can-not-catch-exception/
- qingchen 2018-07-24 已签到连续签到9天,获得了20个金钱
- qingchen 2018-07-22 已签到连续签到7天,获得了20个金钱
- qingchen 2018-07-23 已签到连续签到8天,获得了20个金钱
- qingchen 2018-07-21 已签到连续签到6天,获得了20个金钱
- qingchen 2018-07-20 已签到连续签到5天,获得了20个金钱