public function actionUpdate($id = null) { $model = new Menus(); if ($model->load($_POST)) { $id = $_POST['Menus']['id']; if ($id) { $model = Menus::findOne($id); $model->attributes = $_POST['Menus']; } if ($_POST['Menus']['content']) { $model->urls = 'index.php?r=content/view&id=' . $_POST['Menus']['content']; } else { $model->urls = $_POST['Menus']['urls']; } if ($model->save()) { $this->updateOrder('parent_id=' . $model->parent_id, '&langs=' . $model->langs); return $this->redirect(array('index')); } else { print_r($model->getErrors()); exit; } } if ($id) { $model = Menus::findOne($id); list($a, $b, $c) = explode('=', $model->urls); $model->content = $c; } else { $sess = Yii::$app->session->get('sessMenus'); $model->langs = $sess['langs']; } return $this->render('update', ['model' => $model]); }
public function actionUpdate($type = null, $id = null) { $model = new Menus(); if ($model->load($_POST)) { $id = $_POST['Menus']['id']; if ($id) { $model = Menus::findOne($id); $model->attributes = $_POST['Menus']; } if ($type) { $model->links = $type; } $files = \yii\web\UploadedFile::getInstances($model, 'pics'); if (isset($files) && count($files) > 0) { $mPath = \Yii::getAlias('@webroot') . '/images/icon'; $mUrl = \Yii::getAlias('@web') . '/images/icon'; foreach ($files as $file) { $mFile = substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension; //Upload Images if ($file->saveAs($mPath . '/' . $mFile)) { $model->pics = $mUrl . '/' . $mFile; } } } $model->parent_id = $_POST['Menus']['parent_id'] ? $_POST['Menus']['parent_id'] : 0; if ($model->save()) { $this->updateOrder('parent_id=' . $model->parent_id . ' AND type=' . $model->type); return $this->redirect(array('index')); } else { print_r($model->getErrors()); exit; } } if ($id) { $model = Menus::findOne($id); list($a, $b, $c) = explode('=', $model->urls); $model->content = $c; $type = $model->links; } else { $sess = Yii::$app->session->get('sessMenus'); $model->langs = $sess['langs']; } return $this->render('update', ['model' => $model, 'type' => $type]); }