当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::load方法代码示例

本文整理汇总了PHP中app\models\Post::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::load方法的具体用法?PHP Post::load怎么用?PHP Post::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Post的用法示例。


在下文中一共展示了Post::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
     $currentUser = \Yii::$app->user->identity;
     if (!$currentUser->isAuthor()) {
         //不是 作者 无权操作
         return $this->goHome();
     }
     if ($model->load(Yii::$app->request->post())) {
         if (isset($model->user_id) || $currentUser->id != $model->user_id && !$currentUser->isAdmin()) {
             $model->user_id = $currentUser->id;
         }
         $model->user_id = $currentUser->id;
         //处理slug
         $title = mb_strlen($model->title, 'utf8') > 6 ? mb_substr($model->title, 0, 5) : $model->title;
         $model->slug = \app\helpers\Pinyin::encode($title, 'all');
         while (Post::getPostBySlug($model->slug)) {
             $model->slug .= '-1';
         }
         if ($model->save()) {
             $this->flash('发布成功!', 'info');
             return $this->redirect(['update', 'id' => $model->id]);
         }
     }
     $model->comment_status = Post::COMMENT_STATUS_OK;
     $model->user_id = $currentUser->id;
     return $this->render('create', ['model' => $model, 'isAdmin' => $currentUser->isAdmin()]);
 }
开发者ID:sunjie20081001,项目名称:gudaotu-yii2,代码行数:33,代码来源:PostController.php

示例2: actionCreate

 /**
  * create a post
  *
  * @return null|string|\yii\web\Response
  * @throws Exception
  * @throws \Exception
  */
 public function actionCreate()
 {
     try {
         Yii::trace('Trace :' . __METHOD__, __METHOD__);
         $response = null;
         $model = new Post(['scenario' => 'create']);
         $query = (new Query())->select('name, id')->from('categories')->all();
         $categories = ArrayHelper::map($query, 'id', 'name');
         if ($model->load($_POST) === true && $model->validate() === true) {
             $model->category_id = (int) $model->category_name;
             $model->created = Yii::$app->formatter->asDateTime('now', 'php:Y-m-d H:i:s');
             $model->user_id = Yii::$app->user->id;
             $status = $model->save();
             if ($status === true) {
                 $sidebarCacheName = isset(Yii::$app->params['cache']['sidebar']) ? Yii::$app->params['cache']['sidebar'] : null;
                 if ($sidebarCacheName !== null) {
                     Yii::$app->cache->delete($sidebarCacheName);
                 }
                 $response = $this->redirect(['/post/view', 'slug' => $model->slug]);
             }
         }
         if ($response === null) {
             $response = $this->render('create', ['model' => $model, 'categories' => $categories]);
         }
         return $response;
     } catch (Exception $e) {
         Yii::error($e->getMessage(), __METHOD__);
         throw $e;
     }
 }
开发者ID:artoodetoo,项目名称:BlogMVC,代码行数:37,代码来源:PostController.php

示例3: 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:stanislavdev1993,项目名称:Yii2Blog,代码行数:14,代码来源:PostController.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()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]);
     }
 }
开发者ID:janusnic,项目名称:yii-blog,代码行数:14,代码来源:PostController.php

示例5: update

 /**
  * Update the specified resource in storage.
  *
  * @param  PostFormRequest $request
  * @param  Post $post
  * @return Response
  */
 public function update(PostFormRequest $request, $post)
 {
     $post->fill($request->all());
     $post->save();
     if ($tags = $request->input('tags')) {
         $post->retag($request->input('tags'));
     }
     return $post->load('tagged');
 }
开发者ID:xEdelweiss,项目名称:my-perfect-back-end,代码行数:16,代码来源:PostsController.php

示例6: actionCreate

 public function actionCreate()
 {
     $model = new Post();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list']);
     } else {
         $model->status = POST::STATUS_ENABLED;
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:phucnv206,项目名称:thoitrang,代码行数:10,代码来源: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();
     $model->author_name = Yii::$app->user->identity->nickname;
     if ($model->load(Yii::$app->request->post())) {
         $model->author_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:heartshare,项目名称:yii2-crazydb-blog,代码行数:17,代码来源: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();
     $createdAt = time();
     $model->created_at = $createdAt;
     $model->updated_at = $createdAt;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->saveCategoriesList($model);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'categoriesList' => $this->getCategoriesList()]);
     }
 }
开发者ID:olegigm,项目名称:ghHackathon,代码行数:18,代码来源: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();
     if ($model->load(Yii::$app->request->post())) {
         $model->datetime = date("Y-m-d H:i:s");
         $model->Participant_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
         //die(var_dump($model->getErrors()));
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:pyw5pkU9PcdW,项目名称:COMP3421,代码行数:19,代码来源: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()) {
         /** @var Category[] $categories */
         $categories = Category::find()->where(['id' => $model->categories_id])->all();
         foreach ($categories as $category) {
             $model->link('categories', $category);
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'category_names' => ArrayHelper::map(Category::find()->all(), 'id', 'name')]);
     }
 }
开发者ID:viktornord,项目名称:gh-php-hackaton-basic,代码行数:19,代码来源: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();
     $post = Yii::$app->request->post();
     if ($model->load($post)) {
         $model->user_id = $userId = \Yii::$app->user->identity->id;
         if ($model->save()) {
             return $this->redirect(Yii::$app->request->referrer);
         }
     } elseif (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     } else {
         return $this->render('_form', ['model' => $model]);
     }
 }
开发者ID:skony20,项目名称:olgaz2,代码行数:20,代码来源: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->create_at = $model->update_at = $model->reply_at = time();
     $model->user_id = User::getCurrentId();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($model->point_id > 0) {
             $point = Point::findOne($model->point_id);
             $point->post_num += 1;
             $point->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'point' => Point::findOne(isset($_GET['point']) ? $_GET['point'] : '')]);
     }
 }
开发者ID:nantmpeter,项目名称:lbsbbs,代码行数:21,代码来源:PostController.php

示例13: actionNew

 public function actionNew()
 {
     $postModel = new Post();
     $category = new Category();
     $categoryList = ArrayHelper::map($category->find()->asArray()->all(), 'id', 'title');
     $postList = $postModel->find()->asArray()->all();
     $message = '';
     if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
         $selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
         foreach ($selectedCategories as $category) {
             $postModel->link('categories', $category);
         }
         $message = 'Category added success';
     }
     return $this->render('new', ['model' => $postModel, 'message' => $message, 'categoryList' => $categoryList, 'postList' => $postList]);
 }
开发者ID:stanislavdev1993,项目名称:blog,代码行数:16,代码来源:PostController.php

示例14: 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();
     $pages = Page::find()->all();
     $request = Yii::$app->request;
     $model->page_id = $request->get('page_id');
     $model->create_date = mktime();
     $model->update_date = mktime();
     if ($model->load(Yii::$app->request->post())) {
         $model->create_date = strtotime($model->create_date);
         $model->update_date = strtotime($model->update_date);
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'pages' => $pages]);
     }
 }
开发者ID:sanmaowang,项目名称:ycjl,代码行数:23,代码来源:PostController.php

示例15: 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())) {
           $image = UploadedFile::getInstance($model, 'foto_konten');
           if ($model->save() && $model->upload()) {
               return $this->redirect(['site/index']);
           }
       } else {
           return $this->render('create', [
               'model' => $model,
           ]);
       }*/
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['site/index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:rifkiaputri,项目名称:Lost-and-Found,代码行数:24,代码来源:PostController.php


注:本文中的app\models\Post::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。