Newly Set Primary Key Not Saving

hi im new to yii…

can someone pls help me…

Im trying to programmatically increment a defined primary key to a model with contents from a view…but sadly, it doesnt save…

ur help is much appreciated :)

here is my code on the controller:





        $count = $model->countAllDocNoPattern($model->getAttribute('DocNo'));

        $count1 = sprintf('%04d', $count); 

        $newDocNo = $model->getAttribute('DocNo') .'-'.$count1;








if( $model->save() ) {


} else {

  var_dump( $model->errors );


and you should see validation errors if there are any…

OMG…i was searching for hours…thanks for this…

a maximum validation is blocking me to save it… thank you!!!

of course “var_dump” is only for debug purpose :) In real world you should provide some more user-friendly messages (like showing them near form fields like Gii generator does by default)