public function actionCreateContact($id) { $customerContact = new CustomerContact(); $contact = new Contact(); $customer = Customer::model()->findByPk($id); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($customerContact)); if (isset($_POST['Contact']) && isset($_POST['CustomerContact'])) { $trans = Yii::app()->db->beginTransaction(); try { $contact->attributes = $_POST['Contact']; $customerContact->attributes = $_POST['CustomerContact']; if ($customerContact->save()) { $contact->parent_model = 'CustomerContact'; $contact->parent_id = $customerContact->id; if ($contact->save()) { $trans->commit(); UserLogs::createLog('create new ' . get_class($contact) . ' ' . $contact->primaryKey); Yii::app()->user->setFlash('success', 'Contact Customer sudah ditambah.'); $this->redirect(array('customer/update', 'id' => $id)); } else { throw new CustomerControllerException($contact->getErrors()); } } else { throw new CustomerControllerException($customerContact->getErrors()); } } catch (CustomerControllerException $e) { $trans->rollback(); } catch (CDbException $e) { $trans->rollback(); } } $customerContact->customer_id = $id; $this->render('create_contact', array('contact' => $contact, 'customerContact' => $customerContact, 'id' => $id, 'customer_name' => $customer->name)); }