Hi ,
I have an issue in storing auto generated to DB. Save()is unsuccessful.
Please help.
Vic
[b]ERROR
Creating default object from empty value (C:\xampp\htdocs\mylls1\protected\controllers\homeController.php:89)
User.php [/b]
// model//
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, password','required','on'=>'create'),
[b]array('email,fname,lname,password','required','on'=>'instant_create'),[/b]
//array('email','email'),
array('email, password', 'length', 'max'=>256),
array('email', 'unique'),
array('password', 'compare'),
array('fname,lname, password_repeat', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, email, password, fname,lname', 'safe', 'on'=>'search'),
);
}
// Controller Code //
$model2=new User('instant_create');
// Auto password creation//
$length = 10;
$chars = array_merge(range(0,9), range('a','z'), range('A','Z'));
shuffle($chars);
$password = implode(array_slice($chars, 0, $length));
$model2->attributes=$data;
$model2->email=$_POST['email'];
$model2->fname=$_POST['fname'];
[b] $model->password= md5($password);[/b]
$model2->lname=$_POST['lname'];
$model2->save();
Side Note:
If I remove password from model and controller , I can store rest of the attributes successfully.