public function actionAdd() { $model = new Link(); if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('add', ['model' => $model]); } }
/** * Short URL via Ajax * * @return array Data * @throws BadRequestHttpException If model not validated */ public function actionShort() { $model = new Link(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && $model->save()) { $model->short_code = base_convert($model->id, 20, 36); $model->save(false); Yii::$app->response->format = Response::FORMAT_JSON; return ['shortUrl' => Url::to(['site/go', 'shortCode' => $model->short_code], true)]; } throw new BadRequestHttpException('Bad parameters'); }
/** * Creates a new Link model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id = null) { $model = new Link(); if ($id) { $model->block_id = (int) $id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['block/index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Link model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $menuId * @return mixed */ public function actionCreate($menuId) { $model = new Link(); if ($model->load(Yii::$app->request->post())) { $model->menu_id = $menuId; if ($model->save()) { return $this->redirect(['menu/view', 'id' => $model->menu_id]); } } else { return $this->render('create', ['model' => $model, 'menu' => Menu::findOne($menuId)]); } }
/** * Creates a new Link model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Link(); if ($model->load(Yii::$app->request->post())) { $image = UploadedFile::getInstance($model, 'logo'); if (!empty($image->name)) { $dir = BASE_PATH . '/upload/link/'; if (!is_dir($dir)) { @mkdir(dirname($dir), 0777); @mkdir($dir, 0777); touch($dir . '/index.html'); } $name = date('His') . strtolower(Common::random(16)) . strrchr($image->name, '.'); $image->saveAs($dir . $name); $model->logo = 'upload/link/' . $name; } if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }