/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Menu(); $model->create_user = Yii::$app->user->getId(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $saved = true; $model->imagenes = UploadedFile::getInstances($model, 'imagenes'); foreach ($model->imagenes as $imagen) { $image = new Imagen(); $rnd = rand(0, 99999999); $path = Yii::$app->basePath . '/web/images'; if (!file_exists($path)) { mkdir($path, 0777); } $path = $path . '/Menu'; if (!file_exists($path)) { mkdir($path, 0777); } $path = $path . '/' . $model->id; if (!file_exists($path)) { mkdir($path, 0777); } $imagen->saveAs($path . '/' . $rnd . '.' . $imagen->extension); $image->ur_imagen = $rnd . '.' . $imagen->extension; $image->save(); } if ($saved) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'index' page. * * @return mixed */ public function actionCreate() { $model = new Menu(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'id' => $model->id]); } return $this->redirect(['index']); }
public function actionCreate() { $model = new Menu(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $this->view->title = Yii::t('app', 'Create Menu'); $model = new Menu(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new Menu(); $links = Menu::find()->noParents()->active()->all(); $links = ArrayHelper::map($links, 'id', 'label'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'links' => $links]); } }
public function actionCreate() { $model = new Menu(); $model->attributes = Yii::$app->request->post(); if ($model->save()) { //TODO 是否必须成功创建模板文件,暂时只执行创建逻辑,不判断结果 $tplHelp = new TplHelp(); $tplHelp->create($model->url, $model->id); $this->data['id'] = yii::$app->db->getLastInsertID(); return $this->ok('增加成功'); } else { return $this->error(array_values($model->getFirstErrors())); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!$this->is_access('menu/create')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $model = new Menu(); if ($model->load(Yii::$app->request->post()) && $model->save()) { \backend\models\UserLog::addData('menu', $model->menu_id, "新增菜单[{$model->title}]", 'add'); Yii::$app->session->setFlash('success', '创建菜单成功'); return $this->redirect(['index']); } else { Yii::$app->view->params['meta_title'] = '创建菜单'; $menuTop = $model->menuTop(); return $this->render('create', ['model' => $model, 'menuTop' => $menuTop]); } }
/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCrear() { $model = new Menu(); $modelPaginas = new Paginas(); if ($model->load(Yii::$app->request->post())) { $post = Yii::$app->request->post('Menu'); $model->nombre = $post['nombre']; $model->clase = !empty($post['clase']) ? $post['clase'] : ''; $model->enlace = !empty($post['url']) ? $post['url'] : '#'; $model->target = !empty($post['target']) ? $post['target'] : '_self'; $model->padre = !empty($post['padre']) ? $post['padre'] : 0; /* echo '<pre>'; print_r($post); echo '</pre>'; die(); */ if ($model->save()) { return $this->redirect(['view', 'id' => $model->id_menu]); } } else { return $this->render('crear', ['model' => $model, 'modPaginas' => $modelPaginas]); } }