I am trying to create a user registration script, my user table looks like this
CREATE TABLE IF NOT EXISTS `user` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`username` varchar(25) NOT NULL,
`password` varchar(72) NOT NULL,
`email` varchar(64) NOT NULL,
`create_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`localeid` varchar(5) NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`,`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
and the register action like
public function actionRegister()
{
$model=new User;
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('site/index'));
}
$this->render('register',array('model'=>$model));
}
now i believe the problem is what i have in my model. this is my method for validation rules
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, email', 'required'),
array('username', 'length', 'max'=>25),
array('password', 'length', 'max'=>72),
array('email', 'length', 'max'=>64),
array('create_time, update_time, localeid, status', 'safe'),
);
}
The record is created but if i uncomment this method i added
public function beforeSave()
{
$this->localeid = Yii::app()->locale->getId();
$this->status = 1;
}
and submit the form then the form is just redisplayed and no error message is shown, yet the record will not be created in the DB. so is what i did in the beforeSave method wrong? if so, how can i set those fields in the model?