当前位置: 首页>>代码示例>>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;未经允许,请勿转载。