/** * Creates a new CustomerRecord model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CustomerRecord(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
private function store(Customer $customer) { $customer_record = new CustomerRecord(); $customer_record->name = $customer->name; $customer_record->birth_date = $customer->birth_date->format('Y-m-d'); $customer_record->notes = $customer->notes; $customer_record->save(); foreach ($customer->phones as $phone) { $phone_record = new PhoneRecord(); $phone_record->number = $phone->number; $phone_record->customer_id = $customer_record->id; $phone_record->save(); } }
public function store(Customer $customer) { $customer_record = new CustomerRecord(); // я бы заменил на массив attributes который предоставляет ActiveRecord $customer_record->name = $customer->name; $customer_record->birth_date = $customer->birth_date->format('Y-m-d'); $customer_record->notes = $customer->notes; $customer_record->save(); foreach ($customer->phones as $phone) { $phone_record = new PhoneRecord(); $phone_record->number = $phone->number; $phone_record->customer_id = $customer_record->id; $phone_record->save(); } }