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


PHP News::save方法代码示例

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


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

示例1: postSave

 public function postSave(Request $request)
 {
     if (!empty($this->name) && !empty($this->category) && !empty($this->content) && !empty($this->user_id)) {
         $table = new Models\News();
         $table->name = $this->name;
         $table->create_time = date("Y-m-d H:i:s");
         $table->group_news_id = $this->category;
         $table->images = $this->images;
         $table->slug = $this->slug;
         $table->description = $this->description;
         $table->content = $this->content;
         $table->user_id = $this->user_id;
         $table->keywords = $this->keywords;
         $table->status = 1;
         // 2 : không chọn , 1 là được chọn
         $rs = $table->save();
         $LastInsertId = $table->id;
         $data = ['id' => $LastInsertId, 'name' => $this->name, 'create_time' => date("Y-m-d H:i:s"), 'group_news_id' => $this->category, 'images' => $this->image, 'description' => $this->description, 'content' => $this->content, 'status' => 1];
         if ($rs) {
             return $this->ResponseData($data);
         }
         $this->error = true;
         $this->error_message = "Lỗi truy vấn, vui lòng thử lại sau";
         return $this->ResponseData([]);
     }
     $this->error = true;
     $this->error_message = "Dữ liệu gửi lên không đúng, vui lòng thử lại";
     return $this->ResponseData([]);
 }
开发者ID:dao94,项目名称:game,代码行数:29,代码来源:NewsController.php

示例2: actionCreate

 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     $loaded = $model->load(Yii::$app->request->post());
     if ($loaded) {
         if ($model->is_published) {
             $model->published = date('Y-m-d H:i:s');
         }
     }
     if ($loaded && $model->save()) {
         $model->upload();
         $category_relations = $_POST['News']['categories'];
         foreach ($category_relations as $cat_id) {
             $category_relation = new CategoryRelations();
             $category_relation->news_id = $model->id;
             $category_relation->category_id = $cat_id;
             $category_relation->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $categories_arr = Category::find()->asArray()->all();
         foreach ($categories_arr as &$cat) {
             $categories[$cat['id']] = $cat['name'];
         }
         $model->is_published = 1;
         return $this->render('create', compact('model', 'categories'));
     }
 }
开发者ID:sahartak,项目名称:armbuy,代码行数:33,代码来源:NewsController.php

示例3: actionUpdatenews

 public function actionUpdatenews()
 {
     $data = [];
     if (!empty($_POST['title']) and !empty($_POST['text']) and isset($_GET[id])) {
         $data['id'] = $_GET['id'];
         $data['title'] = $_POST['title'];
         $data['text'] = $_POST['text'];
         $data['datatime'] = date('Y-m-d H:i:s');
     } else {
         $error_report = 'Не указано как и какую новость необходимо обновить';
     }
     if (isset($data['title']) && isset($data['text']) && isset($data['datatime']) && !isset($eror_report)) {
         $news = new NewsModel();
         $news->id = $data['id'];
         $news->title = $data['title'];
         $news->text = $data['text'];
         $news->datatime = $data['datatime'];
         $news->save();
         header('Location: /');
         die;
     } else {
         $view = new View();
         $view->error_report = $eror_report;
         $view->display('second/error.php');
     }
 }
开发者ID:Nilop,项目名称:mvctest,代码行数:26,代码来源:Admin.php

示例4: actionNews

 public function actionNews()
 {
     for ($i = 1; $i <= 10; $i++) {
         $model = new News();
         $model->attributes = ['name' => 'Bài viết số ' . $i, 'title' => 'Title cua bai viet so ' . $i, 'slug' => 'bai-viet-so-' . $i, 'images' => '3.png', 'type_id' => rand(1, 100), 'user_id' => '1', 'created_at' => time(), 'updated_at' => time()];
         $model->save();
     }
 }
开发者ID:lyhoi2204,项目名称:yii2,代码行数:8,代码来源:FakeController.php

示例5: actionSuggest

 public function actionSuggest()
 {
     $model = new News(['status' => News::STATUS_DRAFT, 'scenario' => News::SCENARIO_SUGGEST]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('news.news_successfully_added');
         return $this->redirect(['index']);
     }
     return $this->render('suggest', ['model' => $model]);
 }
开发者ID:Rudianasaja,项目名称:yiifeed,代码行数:9,代码来源:NewsController.php

示例6: actionCreate

 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return Json::encode(['success' => true, 'message' => 'Created!']);
     } else {
         return Json::encode(['success' => false, 'content' => $this->renderPartial('_form', ['model' => $model])]);
     }
 }
开发者ID:artpro676,项目名称:simple_blog,代码行数:14,代码来源:NewsController.php

示例7: actionCreate

 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:secondsano,项目名称:unico-yii,代码行数:14,代码来源:NewsController.php

示例8: actionSave_news

 public function actionSave_news()
 {
     $news = new News();
     $news->title = $_POST['title'];
     $news->content = $_POST['content'];
     $news->createTime = date('Y-m-d H:i:s');
     $news->tag = 'unnecessary';
     $news->save();
     echo 1;
 }
开发者ID:garydai,项目名称:yii2.0-backend,代码行数:10,代码来源:NewsController.php

示例9: actionCreate

 protected function actionCreate()
 {
     try {
         $article = new News();
         $article->fill([]);
         $article->save();
     } catch (MultiException $e) {
         $this->view->errors = $e;
     }
     echo $this->view->render(__DIR__ . '/../templates/update.php');
 }
开发者ID:mr-kamc,项目名称:php2.zz,代码行数:11,代码来源:Admin.php

示例10: actionCreate

 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new News();
     if ($model->load(Yii::$app->request->post())) {
         $model->addedat = date("Y-m-d H:i:s");
         $model->addedby = Yii::$app->user->identity->username;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:eesast,项目名称:ts17web,代码行数:17,代码来源:NewsController.php

示例11: actionCreate

 /**
  * Действие для добовления новости
  *
  */
 protected function actionCreate()
 {
     if ($this->isPost()) {
         try {
             $news = new News();
             $news->fill($_POST);
             $news->save();
             $this->redirect('/Admin');
         } catch (MultiException $error) {
             $this->view->errors = $error;
         }
     } else {
         $this->view->errors = null;
     }
     $this->view->display(__DIR__ . '/../Templates/News/Create.php');
 }
开发者ID:RayManOff,项目名称:my-blog,代码行数:20,代码来源:Admin.php

示例12: createNews

 public function createNews()
 {
     if (!$this->checkLogin()) {
         return redirect('login');
     }
     $item = new News();
     $item->nTitle = Request::input('title');
     $item->catId = Request::input('catId');
     if ($item->catId == null) {
         $item->catId = 1;
     }
     $item->nDescrHTML = Request::input('content');
     if ($item->nTitle != null && $item->nDescrHTML != null && $item->catId != null) {
         $item->save();
     }
     return redirect('news');
 }
开发者ID:haclongkim,项目名称:newsedu,代码行数:17,代码来源:NewsController.php

示例13: create

 public function create(Request $request)
 {
     $clientId = Authorizer::getClientId();
     $operatorId = (int) Authorizer::getResourceOwnerId();
     $data = $request->all();
     $validator = Validator::make($data, ['content' => 'required', 'link_url' => 'url', 'type' => 'in:0,1']);
     if ($validator->fails() === true) {
         return response()->json(['error' => $validator->errors()], 400);
     }
     if (!isset($data['type'])) {
         $data['type'] = 0;
     }
     $data['app_id'] = $clientId;
     $data['author_id'] = $operatorId;
     $data['content'] = preg_replace('/<(.+?)>|<(\\/.+?)>/', '&lt;$1&gt;', $data['content']);
     $news = new News($data);
     $news->save();
     $news = $this->unfoldNewsInfo($news);
     return response()->json($news, 201);
 }
开发者ID:xiyou-linuxer,项目名称:cs-restful-api,代码行数:20,代码来源:NewsController.php

示例14: actionKhoahoctv

 /**
  * This command echoes what you have entered as the message.
  * @param string $message the message to be echoed.
  */
 public function actionKhoahoctv()
 {
     for ($i = 16655; $i <= 70000; $i++) {
         $crawler = new Crawl();
         $crawler->arr_att_clean = array('script', '.thumblock');
         $url = 'http://khoahoc.tv/quan-the-tu-vien-meteora-' . $i;
         $namepath = '/html/body/div[1]/div[3]/div[1]/h1';
         $contentpath = '/html/body/div[1]/div[3]/div[1]/div[3]';
         $type_path = '/html/body/div[1]/div[3]/div[1]/div[2]/span[3]/a';
         if (!@($name = $crawler->getTitle($url, $namepath))) {
             echo 'error_' . $i . "\n";
         } else {
             $name = rUrl::utf8($crawler->getTitle($url, $namepath));
             $content = $crawler->getTitle($url, $contentpath);
             $type = $crawler->getTitle($url, $type_path);
             $content = $crawler->removeLink($content);
             $images = $crawler->getImagesFromMeta($url);
             $keywords = $crawler->getKeywords($url);
             $descriptionmeta = $crawler->getDescriptionmeta($url);
             $type_slug = rUrl::slug($type);
             $mType = Type::find()->Where(['LIKE', 'slug', $type_slug])->one();
             $id_type = $mType['id'];
             $slug = rUrl::slug($name);
             if ($id_type !== null) {
                 $id_type = $mType['id'];
             } else {
                 $id_type = 22;
             }
             $model = new News();
             $model->attributes = ['name' => $name, 'slug' => $slug, 'images' => $images, 'description' => $content, 'seo_keywords' => $keywords, 'view_count' => rand(1000, 10000), 'source' => 'kh', 'seo_title' => $descriptionmeta, 'type_id' => $id_type, 'user_id' => 1, 'hot' => 0, 'post_final' => $i, 'created_at' => time(), 'updated_at' => time()];
             $model->save();
             echo "ok_" . $i . "\n";
             // exit();
         }
     }
 }
开发者ID:lyhoi2204,项目名称:yii2,代码行数:40,代码来源:CrawleController.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @param News $news
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, News $news)
 {
     $news->fill($request->all());
     $news->save();
     return redirect()->route('admin.news.index');
 }
开发者ID:lyovkin,项目名称:elcoinbank,代码行数:13,代码来源:AdminNewsController.php


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