public static function charView($idkey, $model_id) { $array = Characteristics::values($idkey, $model_id); $arr = ''; foreach ($array as $item) { if ($item['parent_id'] == 0) { $arr = $arr . '<b>' . $item['characteristic_name'] . '</b><br/>'; } else { if (isset($item['value'])) { $arr = $arr . ' ' . $item['characteristic_name'] . ' - ' . '<b>' . $item['value'] . '</b>' . ' ' . $item['unit'] . '<br/>'; } } } return $arr; }
/** * 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($category, $id, $brand) { $model = $this->loadModel($id); $modelChar = Characteristics::values($category, $id); if (isset($_POST['Models'])) { $model->attributes = $_POST['Models']; $model->description = $_POST['Models']['description']; $acces = explode(',', $_POST['Models']['accessories']); $accessories = array(); foreach ($acces as $item) { $accessories[] = trim($item); } $model->accessories = json_encode($accessories); if ($model->save()) { if (isset($_POST['characteristicValue'])) { foreach ($_POST['characteristicValue'] as $k => $item) { $modelCharVal = CharacteristicValue::model()->updateAll(array('value' => $item), 'characteristic_id = :k AND model_id = :id', array(':k' => $k, ':id' => $id)); } if (isset($modelCharVal)) { $this->refresh(); } } } } $this->render('update', array('model' => $model, 'category' => $category, 'modelChar' => $modelChar, 'brand' => $brand)); }