Is ‘id’ attribute of the model the primary key? If so, it is not set until it is saved (i.e., inserted into the table with a new primary key). So the “default” rule does not work as you expect.
In your current code of “actionCreate”, you set $model->nummer with the value of $model->id. It’s OK. But the model is not saved after $model->nummer has been set. You have to save the model twice:
public function actionCreate()
{
$model = new Kunde();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->nummer=$model->id;
$model->save(false); // this is it!
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
But, well, do you really need ‘nummer’ attribute? Why don’t you directly access ‘id’?