Hello,
I have users table in which, along with other info, I am also saving users’ pictures. Users can register from application registration form or using facebook connect. The application’s registration form have a file field which is used to upload user’s picture. So, in the Model’s validation rules I have specified it as file. following is my rules function for Users model
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('Username, Name, Email, Passwd', 'length', 'max'=>255),
array('Role', 'length', 'max'=>5),
array('Picture', 'file', 'types'=>'jpg, gif, png'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('Id, Username, Name, Email, Passwd, Role', 'safe', 'on'=>'search'),
);
}
The problem is that when I save information of a user who registers through facebook connect, I get an error about Picture since its a string in this case. Following is piece of code for inserting facebook user’s record.
$model = new Users;
$model->Name = $user['name'];
$model->Source = Users::FACEBOOK;
$model->OAuth_Uid = $user['id'];
$model->Status = Users::ACTIVE;
$model->Role = "user";
$model->Picture = 'http://graph.facebook.com/'.$user['id'].'/picture';
if(!$model->save()){
var_export($model->getErrors());
}
Is there a way to handle this?
Thanks.