/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); 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 Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); if ($model->load(Yii::$app->request->post())) { $model->data = date('Y-m-d h:i:s'); $model->user_id = Yii::$app->user->getId(); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id, 'user_id' => $model->user_id]); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); //$data = new Category(); //$data = Category::find()->all(); if ($model->load(Yii::$app->request->post())) { $model->create_time = time(); $model->user_id = \Yii::$app->user->id; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { //print_r(CKEditor::className()); //print_r(Yii::$classMap['yii\web\Controller']); $model = new Content(); //print_r(Yii::$app->request->post()); if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { if ($model->save()) { //TODO echo '成功'; } } return $this->render('index', ['model' => $model]); }
public function actionUpdate($id = null) { $model = new Content(); if ($model->load($_POST)) { $id = $_POST['Content']['id']; if ($id) { $model = Content::find($id); $model->attributes = $_POST['Content']; } if ($model->save()) { return $this->redirect(array('index')); } else { print_r($model->getErrors()); exit; } } if ($id) { $model = Content::find(['id' => $id]); } return $this->render('update', ['model' => $model]); }