public function actionProdList() { $id = $_POST['provider_id']; $products = Provideprod::model()->with('products.measure')->findAll('provider_id = :provider_id', array(':provider_id' => $id)); $this->renderPartial('providerProdList', array('products' => $products)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $chosenProduct = Provideprod::model()->with('products')->findAll('provider_id = :provider_id', array(':provider_id' => $id)); $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Provider'])) { $messageType = 'warning'; $message = "There are some errors "; $transaction = Yii::app()->db->beginTransaction(); try { $model->attributes = $_POST['Provider']; $messageType = 'success'; $message = "<strong>Well done!</strong> You successfully update data "; /* $uploadFile=CUploadedFile::getInstance($model,'filename'); if(!empty($uploadFile)) { $extUploadFile = substr($uploadFile, strrpos($uploadFile, '.')+1); if(!empty($uploadFile)) { if($uploadFile->saveAs(Yii::app()->basePath.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.'provider'.DIRECTORY_SEPARATOR.$model->provider_id.DIRECTORY_SEPARATOR.$model->provider_id.'.'.$extUploadFile)){ $model->filename=$model->provider_id.'.'.$extUploadFile; $message .= 'and file uploded'; } else{ $messageType = 'warning'; $message .= 'but file not uploded'; } } } */ if ($model->save()) { if (isset($_POST['product_id'])) { Provideprod::model()->deleteAll('provider_id = :provider_id', array(':provider_id' => $id)); foreach ($_POST['product_id'] as $value) { $prodModel = new Provideprod(); $prodModel->provider_id = $model->provider_id; $prodModel->prod_id = $value; $prodModel->save(); } } $transaction->commit(); Yii::app()->user->setFlash($messageType, $message); $this->redirect(array('view', 'id' => $model->provider_id)); } } catch (Exception $e) { $transaction->rollBack(); Yii::app()->user->setFlash('error', "{$e->getMessage()}"); // $this->refresh(); } $model->attributes = $_POST['Provider']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->provider_id)); } } $this->render('update', array('chosenProduct' => $chosenProduct, 'model' => $model)); }