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


PHP Article::load方法代码示例

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


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

示例1: 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())) {
         $photo = UploadedFile::getInstances($model, 'photo');
         $images = UploadedFile::getInstances($model, 'images');
         $model->url = $this->SlugHelperUrl($model->title);
         $model->created = date('Y-m-d H:i:s');
         if ($photo) {
             $photo[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension);
             $model->photo = Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension;
         } else {
             Yii::trace($photo->errors);
         }
         if ($images) {
             $images[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $images[0]->extension);
             $model->images = Yii::$app->user->identity->id . '_im' . time() . '.' . $images[0]->extension;
         } else {
             Yii::trace($photo->errors);
         }
         if ($model->photo != '' && !file_exists(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo) && file_exists(__DIR__ . '/../../../web/upload/article/' . $model->photo)) {
             $thumb = new Imagick(__DIR__ . '/../../../web/upload/article/' . $model->photo);
             $thumb->resizeImage(300, 174, Imagick::FILTER_LANCZOS, 1);
             $thumb->writeImage(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo);
             $thumb->destroy();
         }
         $model->save();
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:efabrikov,项目名称:chomu,代码行数:37,代码来源:ArticleController.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(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:frankpaul142,项目名称:chaide,代码行数:14,代码来源:ArticleController.php

示例3: actionCreate

 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = 'admin';
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['browse']);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all()]);
     }
 }
开发者ID:samatic,项目名称:yii2-starter,代码行数:15,代码来源:ArticleController.php

示例4: actionUpdate

 public function actionUpdate($id = null)
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post())) {
         $request = Yii::$app->request->post('Article');
         $id = $request['id'];
         if ($id) {
             $model = Article::findOne($id);
             $model->attributes = $request;
         }
         if ($model->save()) {
             $this->updateOrder('cid=' . $model->cid, '&langs=' . $model->langs);
             $files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
             if (isset($files) && count($files) > 0) {
                 $mPath = \Yii::getAlias('@webroot') . '/images/article/news_' . $model->id;
                 if (!is_dir($mPath)) {
                     \yii\helpers\BaseFileHelper::createDirectory($mPath);
                 }
                 foreach ($files as $file) {
                     if ($request['cid'] == '12') {
                         $mPic = $file->baseName . '.' . $file->extension;
                     } else {
                         $mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
                     }
                     //Upload Images
                     if ($file->saveAs($mPath . '/' . $mPic)) {
                         $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                         $image->resize(1024, 1024);
                         $image->save($mPath . '/' . $mPic);
                         //resize images thumb
                         $image = \Yii::$app->image->load($mPath . '/' . $mPic);
                         $image->resize(250, 250);
                         $mThumb = $mPath . '/thumb/';
                         if (!is_dir($mThumb)) {
                             \yii\helpers\BaseFileHelper::createDirectory($mThumb);
                         }
                         $image->save($mThumb . $mPic);
                     }
                 }
             }
             return $this->redirect(array('index'));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     if ($id) {
         $model = Article::findOne($id);
     } else {
         $sess = Yii::$app->session->get('sessArticle');
         $model->langs = $sess['langs'];
         $model->cid = $sess['cid'];
     }
     return $this->render('update', ['model' => $model]);
 }
开发者ID:jatuponp,项目名称:rgweb,代码行数:55,代码来源:ArticleController.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();
     $tourtype = new Tourtype();
     $small = new FileUpload();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'tourtype' => $tourtype, 'small' => $small]);
     }
 }
开发者ID:nguyendtu,项目名称:VietvietTravel,代码行数:16,代码来源:ArticleController.php

示例6: 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->preview_input = UploadedFile::getInstance($model, 'preview_input');
         if (!empty($model->preview_input)) {
             $model->preview_picture = 'preview/' . $model->preview_input->baseName . '.' . $model->preview_input->extension;
         }
         if ($model->save()) {
             Yii::warning("Article changed. Attributes = " . print_r($model->attributes));
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:amarchenkov,项目名称:myCMS,代码行数:20,代码来源:ArticleController.php

示例7: 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();
     $uploader = new Uploader();
     if (Yii::$app->request->isPost) {
         $uploader->imageFile = UploadedFile::getInstance($uploader, 'imageFile');
         $model->user_id = Yii::$app->user->identity->id;
         $model->date = date("Y-m-d H:i:s");
         $model->image_tag = $uploader->imageFile->basename;
         $model->image_extension = $uploader->imageFile->extension;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             if ($uploader->upload($model->id)) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:AhmedMH,项目名称:news-portal,代码行数:23,代码来源:ArticleController.php

示例8: 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();
     $model->user_id = Yii::$app->user->id;
     if (Yii::$app->user->can('createArticle', ['model' => $model])) {
         // Check permission before process acction
         if ($model->load(Yii::$app->request->post())) {
             $this->Uploads(false);
             if ($model->save()) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             $model->ref = substr(Yii::$app->getSecurity()->generateRandomString(), 10);
         }
         return $this->render('create', ['model' => $model]);
     } else {
         throw new ForbiddenHttpException('ขอแสดงความเสียใจอย่างสุดซื้ง!, คุณไม่ได้รับอนุญาตให้เข้าใช้งาน');
     }
     /*if ($model->load(Yii::$app->request->post()) && $model->validate()) {
           $model->thumbnail = $model->uploadThumbnail($model,'thumbnail');
           $model->photos = $model->uploadMultipleImg($model,'photos');
           $model->files = $model->uploadMultipleFiles($model,'files');
           $model->save();
           return $this->redirect(['view', 'id' => $model->id]);
       } else {
           return $this->render('create', [
           'model' => $model,
           ]);
       }*/
     /*
     if ($model->load(Yii::$app->request->post()) && $model->save())
     {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     else
     {
         return $this->render('create', [
         'model' => $model,
         ]);
     }
     */
 }
开发者ID:poykub,项目名称:wph,代码行数:48,代码来源:ArticleController.php

示例9: 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())) {
         $categories = new ArticleCategories();
         $model->psychologist_id = Yii::$app->user->id;
         $model->is_owner = 1;
         if ($model->save()) {
             $articleCategories = Yii::$app->request->post('categories');
             if ($categories->saveArticleCategories($model->id, $articleCategories)) {
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
             return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
         }
         /*if ($model->save()) {
               return $this->redirect(['view', 'id' => $model->id]);
           }*/
     } else {
         return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
     }
 }
开发者ID:Akelcehg,项目名称:psycho,代码行数:27,代码来源:ArticleController.php


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