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


PHP Article::save方法代碼示例

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


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

示例1: insert

 /**
  * 將文章插入數據庫
  * @param $title
  * @param $content
  * @param $publish_at
  * @param $tag
  * @return bool
  */
 public static function insert($title, $content, $publish_at, $tag = '')
 {
     //插入標簽(搜索的分類)
     $article = new Article();
     $article->title = $title;
     $article->content = $content;
     $article->author = 'yang';
     $article->status = Article::STATUS_GATHER;
     $article->publish_at = $publish_at;
     $res = $article->save(false);
     if ($tag) {
         try {
             $tagModel = Tag::find()->where(['name' => $tag])->one();
             if (!$tagModel) {
                 $tagModel = new Tag();
                 $tagModel->name = $tag;
                 $tagModel->article_count = 0;
                 $tagModel->save(false);
             }
             $articleTag = new ArticleTag();
             $articleTag->article_id = $article->id;
             $articleTag->tag_id = $tagModel->id;
             $articleTag->save(false);
         } catch (\Exception $e) {
             echo $e->getMessage() . PHP_EOL;
         }
     }
     return $res ? true : false;
 }
開發者ID:specialnote,項目名稱:myYii,代碼行數:37,代碼來源:ArticleSpider.php

示例2: actionCreate

 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'ads' => Ad::find()->all(), 'articles' => Article::find()->all()]);
     }
 }
開發者ID:Brother-Simon,項目名稱:yii2-starter-kit,代碼行數:14,代碼來源:ArticleController.php

示例3: actionCreate

 /**
  * Creates a new ArticleDownload model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($cat_id)
 {
     $model = new ArticleDownload();
     $Article = new Article();
     $postData = Yii::$app->request->post();
     if ($model->load($postData) && $Article->load($postData) && $Article->save() && $model->addData($Article->article_id)) {
         Yii::$app->session->setFlash('success', '添加成功');
         return $this->redirect(['article/index']);
     } else {
         Yii::$app->view->params['meta_title'] = '添加文章';
         return $this->render('create', ['model' => $model, 'Article' => $Article]);
     }
 }
開發者ID:wordnews,項目名稱:wei_shop,代碼行數:18,代碼來源:DownloadController.php

示例4: actionCreate

 public function actionCreate()
 {
     //儲存視頻
     if ($video = Yii::$app->request->post()) {
         $model = new Article();
         $files = Fileupload::upload();
         $video['img'] = isset($files[0]) ? $files[0] : './img/default.jpg';
         $model->set_video_data($video);
         if ($model->save(false)) {
             return $this->render('create', ['msg' => '添加視頻成功!']);
         } else {
             return $this->render('create', ['msg' => '添加視頻失敗,請刷新重試!']);
         }
     } else {
         return $this->render('create');
     }
 }
開發者ID:codekissyoung,項目名稱:filmfest,代碼行數:17,代碼來源:VideoController.php

示例5: actionCreate

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

示例6: insert

 /**
  * 將文章插入數據庫
  * @param $title 標題
  * @param $content 內容
  * @param $publish_at 發布時間
  * @param string $category 分類名
  * @param string $cover 封麵
  * @return int
  */
 public function insert($title, $content, $publish_at, $category = '', $cover = '')
 {
     //插入標簽(搜索的分類)
     $categoryId = (new Category())->getCategoryIdByName($category);
     if (!$categoryId) {
         throw new Exception('該分類不存在');
     }
     $article = new Article();
     $article->title = $title;
     $article->author = '匿名';
     $article->status = 1;
     $article->category = $category;
     $article->category_id = $categoryId;
     $article->source = $this->config['domain'];
     $article->cover = $cover;
     $article->created_at = $publish_at;
     $article->user_id = 0;
     $res = $article->save(false);
     if ($res) {
         $articleData = new ArticleData();
         $articleData->id = $article->id;
         $articleData->content = $content;
         $res = $articleData->save(false);
     }
     return $res ? 1 : 0;
 }
開發者ID:zhangsong,項目名稱:yii,代碼行數:35,代碼來源:SpiderAbstract.php

示例7: actionAddNewsFromParser

 public function actionAddNewsFromParser()
 {
     $result = 0;
     $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json';
     if (file_exists($file)) {
         $ImportModel = file_get_contents($file);
         $obj = json_decode($ImportModel);
         //vd($obj);
         if ($ImportModel) {
             foreach ($obj as $row) {
                 $duble = Blog::getDublicateByTitle($row->title);
                 if (!$duble) {
                     $model = new Article();
                     $model->title = $row->title;
                     $model->image = $row->image ? $row->image : '';
                     $model->content = $row->content;
                     $model->created_at = $row->created_at;
                     $model->updated_at = $row->updated_at;
                     $model->author = $row->author;
                     $model->save();
                     $result = 1;
                 } else {
                     //echo "It is Dublicate", PHP_EOL;
                 }
             }
         }
     }
     return $result;
 }
開發者ID:kotmonstr,項目名稱:kotmonstr,代碼行數:29,代碼來源:DefaultController.php


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