若谷
挺好的,除了有点小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个金钱