I need to add code to the database like this CN492B9ХХХХХХ where XXXXXX number that begins with 000000 and incremented by 1 for each data. This is my controller
public function actionCreate()
{
$model=new DeliveyInfo;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['DeliveyInfo']))
{
$model->attributes=$_POST['DeliveyInfo'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
I ad to the model
public function beforeSave() {
if ($this->isNewRecord)
$this->code = sprintf('CN492B9%06d', $this->id);
return parent::beforeSave();
}
But there is no id number. Where can i get it for the new record?