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


PHP Post::genSlug方法代碼示例

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


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

示例1: actionPostAdd

 /**
  * Url: /post/add
  * @return mixed
  * @throws ForbiddenHttpException
  */
 public function actionPostAdd()
 {
     if (Yii::$app->user->isGuest) {
         throw new ForbiddenHttpException("Вы не можете выполнить это действие.");
     }
     $model = new Post();
     $model->content_category_id = Post::CATEGORY_BLOG;
     $model->tags = [];
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->allow_comment = 1;
         $model->is_public = 1;
         $model->content_category_id = Post::CATEGORY_BLOG;
         $model->user_id = Yii::$app->user->id;
         // Set slug
         $model->slug = $model->genSlug($model->title);
         // Save the model to have a record number
         if ($model->save()) {
             // Adding new tags
             if (is_array($model->tags)) {
                 foreach ($model->tags as $id) {
                     $model->addTag($id);
                 }
             }
             $cached_tag_list = [];
             $newTags = $model->getTags();
             foreach ($newTags as $newTag) {
                 $cached_tag_list[] = $newTag->name;
             }
             $model->cached_tag_list = implode(', ', $cached_tag_list);
             // Set image
             $uploadedFile = UploadedFile::getInstance($model, 'image');
             if ($uploadedFile) {
                 // Save origionals
                 $asset = new Asset();
                 $asset->assetable_type = Asset::ASSETABLE_POST;
                 $asset->assetable_id = $model->id;
                 $asset->uploadedFile = $uploadedFile;
                 $asset->saveAsset();
                 // Save thumbnails
                 $imageID = $asset->id;
                 $thumbnails = Asset::getThumbnails(Asset::ASSETABLE_POST);
                 foreach ($thumbnails as $thumbnail) {
                     $asset = new Asset();
                     $asset->parent_id = $imageID;
                     $asset->thumbnail = $thumbnail;
                     $asset->assetable_type = Asset::ASSETABLE_POST;
                     $asset->assetable_id = $model->id;
                     $asset->uploadedFile = $uploadedFile;
                     $asset->saveAsset();
                 }
             }
             $model->save(false);
             return $this->redirect($model->getUrl());
         }
         var_dump($model->getErrors());
         die;
     }
     $title = 'Добавить запись в блог';
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['blog_form' => ['view' => '@frontend/views/forms/blog_form', 'data' => compact('model', 'tags', 'title')]], 'columnSecond' => ['blog' => SiteBlock::getBlogPosts(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
 }
開發者ID:alexsynytskiy,項目名稱:Dynamomania,代碼行數:65,代碼來源:SiteController.php


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