强哥,各位YII爱好者 你们好:
我遇到一个问题,希望得到热心人的帮助。
有user profile两个表,在user中’profiles’=>array(self::HAS_ONE, ‘Profile’, ‘userid’),关联了user和profile
在实际项目中遇到以下问题,注册的时候需要输入年龄,是profile的属性,如何验证?如果写rules?
我现在的做法是在 user的model中public $age; rules 添加 array(‘integral, age’, ‘numerical’),
为了在注册的时候验证年龄为数字,
于是,当表单提交时 在用户save成功后
$profile = Profile::model();
$_POST['User']['userId']=$register->id;
$profile->attributes= $_POST['User'];
if($profile->validate()) {
$profile->save();
};
其中$profile->attributes有age选项,profile所有的属性都可以为空。
$profile->save()也返回了 1 但是profile表中就是没有数据,为什么?该如何解决?