若谷

若谷

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

  • 财富值140
  • 威望值0
  • 总积分170

个人信息

  • 挺好的,除了有点小bug,其他完美!!!
    1.修改在Member.php中,在42行左右,也就是验证规则里面加入city的验证。

     public function rules()
    {
    	// NOTE: you should only define rules for those attributes that
    	// will receive user inputs.
    	return array(
    		array('name, province', 'required'),
    		array('province', 'numerical', 'integerOnly'=>true),
    		array('name', 'length', 'max'=>128),
                    array('city','numerical'),
    		// The following rule is used by search().
    		// Please remove those attributes that should not be searched.
    		array('id, name, province, city', 'safe', 'on'=>'search'),
    	);
    }
    
    

    假如不加入对city的验证,则city被过滤掉,插入数据库的值为null。

    mysql> select * from tbl_member;
    +----+-----------+----------+------+
    | id | name      | province | city |
    +----+-----------+----------+------+
    |  1 | Joyven    |       28 | NULL |
    |  2 | hello     |       18 | NULL |
    |  3 | 111       |        7 | NULL |
    |  4 | 121       |       10 | NULL |
    |  5 | 万千瓦    |       12 | NULL |
    +----+-----------+----------+------+
    

    2.修改Member.php的一个方法的返回值。getCityName($id)方法,修改有两处,$id必须转换成int,其二返回值要判断是否有model。

    
    public function getCityName($id)
    {
    	$model = City::model()->findByPk((int)$id);
            return $model?$model->name:null;
    }
    
    

    如果第一条修改了,第二条就不会出现验证问题,因为参数$id就不会为null,单安全考虑,依然期望判断。

     mysql> select * from tbl_member;
     +----+-----------+----------+------+
     | id | name      | province | city |
     +----+-----------+----------+------+
     |  1 | Joyven    |       28 | NULL |
     |  2 | hello     |       18 | NULL |
     |  3 | 111       |        7 | NULL |
     |  4 | 121       |       10 | NULL |
     |  5 | 万千瓦    |       12 | NULL |
     |  6 | 323       |       13 |  129 |
     |  7 | test      |       11 |  105 |
     +----+-----------+----------+------+
    
  • 发表了说说
    又到了星期五~~~~
  • 发表了说说
    累~~~
  • 赞了说说
    下午是不是挂了一会?
  • 2015-07-31 已签到
    连续签到1天,获得了5个金钱
助理 等级规则
170/200
资料完整度
70/100
用户活跃度
10/100

Ta的关注

1

Ta的粉丝

2

Ta的访客

17