public function actionDiscount($id) { $customer = $this->loadModel($id); $services = new ServiceDetail('search'); $services->unsetAttributes(); // clear any default values if (isset($_GET['ServiceDetail'])) { $services->attributes = $_GET['ServiceDetail']; } if (isset($_POST['CustomerDiscount'])) { foreach ($_POST['CustomerDiscount'] as $key => $data) { if (isset($data['id'])) { $model = CustomerDiscount::model()->findByPk($data['id']); } else { $model = new CustomerDiscount(); } $model->setAttributes($data); $model->save(); } } $this->render('discount', array('services' => $services, 'customer' => $customer)); }