當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::save方法代碼示例

本文整理匯總了PHP中common\models\Post::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::save方法的具體用法?PHP Post::save怎麽用?PHP Post::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Post的用法示例。


在下文中一共展示了Post::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionCreate

 /**
  * Creates a new Post model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Post();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create Post success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
開發者ID:hdushku,項目名稱:npai,代碼行數:35,代碼來源:PostController.php

示例2: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'update' page.
  *
  * @param integer $post_type post_type_id
  *
  * @throws \yii\web\ForbiddenHttpException
  * @throws \yii\web\NotFoundHttpException
  * @return mixed
  */
 public function actionCreate($post_type)
 {
     $model = new Post();
     $postType = $this->findPostType($post_type);
     $model->post_comment_status = Option::get('default_comment_status');
     if (!Yii::$app->user->can($postType->post_type_permission)) {
         throw new ForbiddenHttpException(Yii::t('writesdown', 'You are not allowed to perform this action.'));
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->post_type = $postType->id;
         $model->post_date = Yii::$app->formatter->asDatetime($model->post_date, 'php:Y-m-d H:i:s');
         if ($model->save()) {
             if ($termIds = Yii::$app->request->post('termIds')) {
                 foreach ($termIds as $termId) {
                     $termRelationship = new TermRelationship();
                     $termRelationship->setAttributes(['term_id' => $termId, 'post_id' => $model->id]);
                     if ($termRelationship->save() && ($term = $this->findTerm($termId))) {
                         $term->updateAttributes(['term_count' => $term->term_count++]);
                     }
                 }
             }
             if ($meta = Yii::$app->request->post('meta')) {
                 foreach ($meta as $meta_name => $meta_value) {
                     $model->setMeta($meta_name, $meta_value);
                 }
             }
             Yii::$app->getSession()->setFlash('success', Yii::t('writesdown', '{post_type} successfully saved.', ['post_type' => $postType->post_type_sn]));
             return $this->redirect(['update', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'postType' => $postType]);
 }
開發者ID:tampaphp,項目名稱:app-cms,代碼行數:42,代碼來源:PostController.php

示例3: createPost

 public function createPost()
 {
     $newPost = new Post();
     $newPost['title'] = $this->title;
     $newPost['content'] = $this->content;
     $newPost['permit'] = $this->permit[0];
     if ($this->upload()) {
         $newPost['image'] = $this->thumbnail;
     }
     if ($this->date == "") {
         $newPost['create_at'] = date("Y-m-d");
     } else {
         $newPost['create_at'] = $this->date;
     }
     $newPost['user_id'] = $this->user_id;
     $newPost->save();
     if ($newPost['permit'] == 2) {
         foreach ($this->reader as $userId) {
             $newPostProtected = new PostProtected();
             $newPostProtected['create_at'] = $newPost['create_at'];
             $newPostProtected['post_id'] = $newPost['id'];
             $newPostProtected['user_id'] = $userId;
             $newPostProtected->save();
         }
     }
 }
開發者ID:ockor,項目名稱:yii2adv-blog,代碼行數:26,代碼來源:PostCreateForm.php

示例4: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id];
         return $this->redirect($redirect);
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:kibercoder,項目名稱:bilious-octo-fibula,代碼行數:14,代碼來源:PostController.php

示例5: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:nsdown,項目名稱:getyii,代碼行數:14,代碼來源:PostController.php

示例6: actionCreate

 /**
  * Создание поста.
  * @return string|Response
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $model->author_id = Yii::$app->user->id;
         return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'tags' => Tags::find()->all(), 'authors' => User::find()->all()]);
     }
 }
開發者ID:richardcj,項目名稱:Blog-Yii2,代碼行數:14,代碼來源:PostController.php

示例7: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     $user_id = yii::$app->getUser()->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['view', 'model' => $model]);
         return $this->redirect(['index', 'user_id' => $user_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:abwxwx,項目名稱:yiistudy,代碼行數:16,代碼來源:PostController.php

示例8: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     //$authot = new User();
     //$authot->attributes='selected';
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'autor' => User::find()->all()]);
     }
 }
開發者ID:kuzma17,項目名稱:paveldent,代碼行數:16,代碼來源:PostController.php

示例9: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     $categoryModel = new CategoryPost();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]);
     }
 }
開發者ID:nguyentuansieu,項目名稱:OneCMS,代碼行數:16,代碼來源:PostController.php

示例10: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach (Category::getCategoriesById($model->categories_id) as $category) {
             $model->link('categories', $category);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:viktornord,項目名稱:gh-php-blog,代碼行數:17,代碼來源:PostController.php

示例11: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = time();
         $model->updated_at = time();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'category' => Category::find()->all()]);
     }
 }
開發者ID:obepyc,項目名稱:yii2-news,代碼行數:18,代碼來源:PostController.php

示例12: actionCreate

 /**
  * Creates a new Post model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Post();
     $model->type = 'post';
     $model->user_id = \Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post())) {
         $model->category_id = implode(',', $model->category_id);
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:huynhtuvinh87,項目名稱:cms,代碼行數:19,代碼來源:PostController.php

示例13: actionAddPost

 public function actionAddPost()
 {
     $post = new Post();
     $user = Yii::$app->user->identity;
     $post->load(Yii::$app->request->post(), '');
     $post->user_id = $user->id;
     $post->img = UploadedFile::getInstanceByName('image');
     if ($post->save()) {
         if ($post->img) {
             $post->saveImage();
         }
         return $post;
     } else {
         return $post->getErrors();
     }
 }
開發者ID:bolom009,項目名稱:testwork_api,代碼行數:16,代碼來源:PostController.php

示例14: actionCreate

 /**
  * 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 Post();
     $model->allowComment = true;
     $model->allowFeed = true;
     $model->allowPing = true;
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post())) {
             $model->inputCategories = Yii::$app->request->post('inputCategories', []);
             $model->inputTags = Yii::$app->request->post('inputTags', []);
             $model->inputAttachments = Yii::$app->request->post('inputAttachments', []);
             if ($model->save()) {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:Penton,項目名稱:MoBlog,代碼行數:23,代碼來源:PostController.php

示例15: actionCreate

 public function actionCreate($url)
 {
     exit;
     $html = SimpleHtmlDom::file_get_html($url);
     foreach ($html->find('ul[id="news_home"] li') as $item) {
         $model = new Post();
         $image = str_replace('_240x144', null, $item->find('img', 0)->src);
         $model['category_id'] = 1;
         $model['title'] = trim($item->find('a[class="title_tin"]', 0)->plaintext);
         $model['image'] = $this->saveImage($image);
         $detail = $item->find('a[class="title_tin"]', 0)->href;
         $html_detail = SimpleHtmlDom::file_get_html($detail);
         $summary = $html_detail->find('p[class="lead"]', 0)->plaintext;
         $content = strip_tags($html_detail->find('div[class="fck_detail width_common"]', 0)->innertext, '<img><strong><br /><br><p>');
         $model['content'] = $summary . $content;
         $model->save();
     }
 }
開發者ID:nguyentuansieu,項目名稱:OneCMS,代碼行數:18,代碼來源:FakeController.php


注:本文中的common\models\Post::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。