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


PHP News::load方法代碼示例

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


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

示例1: actionCreate

 /**
  * Creates a new News model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (!\Yii::$app->user->isGuest) {
         $model = new News();
         $max = NewsSearch::find()->select('max(id_new)')->scalar() + 1;
         if ($model->load(Yii::$app->request->post())) {
             if ($model->file = UploadedFile::getInstance($model, 'file')) {
                 $model->file->saveAs('images/new-' . $max . '.' . $model->file->extension);
                 $model->smallimg_new = '/images/new-' . $max . '.' . $model->file->extension;
             }
             $model->save();
             return $this->redirect(['view', 'id' => $model->id_new]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
     $model = new LoginForm();
     if ($model->load(\Yii::$app->request->post()) && $model->login()) {
         $searchModel = new NewsSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
開發者ID:hogvarce,項目名稱:news_site,代碼行數:30,代碼來源: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: 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->load($_POST);
         //Дата создания
         $model->date = date('Y-m-d');
         $model->file = UploadedFile::getInstance($model, 'file');
         $filename = Yii::$app->security->generateRandomString() . '.' . $model->file->extension;
         $model->img = $filename;
         $model->file->saveAs(Yii::getAlias('@app') . '/web/img/' . $filename);
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:singleton90,項目名稱:mail_news,代碼行數:22,代碼來源:NewsController.php

示例4: 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

示例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->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

示例8: 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())) {
         if ($model->imageFile = UploadedFile::getInstance($model, 'imageFile')) {
             $model->upload();
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:Everus,項目名稱:idflyTest,代碼行數:18,代碼來源:NewsController.php

示例9: actionCreate

 public function actionCreate()
 {
     $model = new News();
     $login = new login();
     $imgLoad = new imgLoad();
     if (Yii::$app->user->identity->level > 1) {
         if ($model->load(Yii::$app->request->post()) && $model->create()) {
             if ($imgLoad->load(Yii::$app->request->post())) {
                 if ($imgLoad->file = UploadedFile::getInstance($imgLoad, 'file')) {
                     $imgLoad->img_load($model->id);
                     $model->save_id_img($imgLoad->id);
                 }
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['login' => $login, 'model' => $model, 'imgLoad' => $imgLoad]);
         }
     }
 }
開發者ID:Baron-fon-Kolt,項目名稱:yii2_black,代碼行數:19,代碼來源:NewsController.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->url = UrlHelp::translateUrl($model->name);
         if ($model->validate()) {
             $model->imageFile = UploadedFile::getInstance($model, 'imageFile');
             if ($model->imageFile) {
                 if ($imgName = $model->upload($model->url)) {
                     $model->img = $imgName;
                 }
             }
             $model->imageFile = null;
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
開發者ID:comaw,項目名稱:hashtag,代碼行數:24,代碼來源:NewsController.php

示例11: actionCreate

 public function actionCreate()
 {
     $model = new News();
     // автоматически сохраняем id автора
     $model->author_id = Yii::$app->user->identity->id;
     if ($model->load(Yii::$app->request->post())) {
         $model->file = \yii\web\UploadedFile::getInstance($model, 'file');
         if ($model->file) {
             $imagePath = 'uploads/';
             $model->image = $imagePath . $model->file->name;
         }
         if ($model->save()) {
             if ($model->file) {
                 $model->file->saveAs($model->image);
             }
             // отправляем письмо модератору с ссылкой на новую статью
             Yii::$app->mailer->compose()->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' Отправлено роботом'])->setTo('galina-sil55@yandex.ru')->setTextBody('Ссылка: http://localhost' . Yii::$app->request->BaseUrl . '/news/' . $model->id)->setSubject('Новая статья')->send();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
開發者ID:silischev,項目名稱:yii2_blog,代碼行數:23,代碼來源:NewsController.php


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