Double insert record in Yii2

Hey! do you need that double insert every time user create

public function actionCreate()
{
$model = new Records();

if($model->load(Yii::$app->request->post()))
{
$model->name = $model->name.’.trustpositifkominfo’;
$model->save();
// second insert here
$clone = new Records;
$clone->attributes = $model->attributes;
$clone->name = ‘*.’.$clone->name;
$clone->save();
return $this->redirect([‘view’, ‘id’ => $model->id]);
}
else {
return $this->render(‘create’, [
‘model’ => $model,
]);
}

}

Create customized field value Yii2

hello! After a long hiatus. I got a project for my office. It is a dashboard application for powerdns. All the records  have only 1 master domain. So, I have to do a trick to put trustpositifkominfo as a domain for every record inserted. here is the magic:

public function beforeSave($insert) {

if ($insert) {
$this->domain_id = 1;
$this->name = $this->name.’.trustpositifkominfo’;
}
return parent::beforeSave($insert);

}

Halo dunia!

Hai! I’m a twenty-something coder girl who has a giant dream. I want to remember all of the logics that I wrote in my yii based application. Don’t hesitate to ask anything that related to my blog post 🙂

Ciao bella!