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


PHP models\Tag类代码示例

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


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

示例1: store

 public function store(Request $request)
 {
     $tag = new Tag();
     $tag->fill($request->all());
     $tag->save();
     return $tag;
 }
开发者ID:Wade-Nairn,项目名称:nibblr-WE06,代码行数:7,代码来源:TagController.php

示例2: actionInit

 public function actionInit()
 {
     $imageList = Image::find()->asArray()->all();
     foreach ($imageList as $image) {
         $rawFilePath = $image['rawFilePath'];
         $match = [];
         if (preg_match('/\\/homeNASDownloads\\/photo_[0-9\\-]+\\/?(.*)/', dirname($rawFilePath), $match)) {
             $tagName = $match[1];
             if (empty($tagName)) {
                 continue;
             }
             $tag = Tag::find()->where(['tagName' => $tagName])->one();
             if ($tag === null) {
                 $tag = new Tag();
                 $tag->tagName = $tagName;
                 $tag->isDelete = false;
                 $now = date('Y-m-d H:i:s');
                 $tag->createTime = $now;
                 $tag->updateTime = $now;
                 $tag->save();
             }
             $imageTag = ImageTag::find()->where(['imageId' => $image['id'], 'tagId' => $tag->id])->one();
             if ($imageTag == null) {
                 $imageTag = new ImageTag();
                 $imageTag->imageId = $image['id'];
                 $imageTag->tagId = $tag->id;
                 $imageTag->isDelete = false;
                 $imageTag->createTime = $now;
                 $imageTag->updateTime = $now;
                 $imageTag->save();
             }
         }
     }
 }
开发者ID:tomjamescn,项目名称:photo_gallery,代码行数:34,代码来源:ImageTagController.php

示例3: setTags

 public static function setTags($entryId, $tags)
 {
     if (!$tags) {
         return;
     }
     // Write new tags to Tag table
     try {
         foreach ($tags as $k => $t) {
             // Add new tag if id is not exist
             if (!isset($t['id'])) {
                 $tag = new Tag();
                 $tag->text = $t['text'];
                 $tag->save();
                 $tags[$k]['id'] = $tag->id;
             }
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
     // Update tags for current entry
     //TODO: rewrite with junction table relations
     try {
         EntryTag::deleteAll(['entry_id' => (int) $entryId]);
         foreach ($tags as $t) {
             $e = new EntryTag();
             $e->tag_id = $t['id'];
             $e->entry_id = $entryId;
             $e->save();
         }
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
开发者ID:Atre,项目名称:uran_test,代码行数:33,代码来源:EntryTag.php

示例4: addTags

 public static function addTags($tags_str, $id)
 {
     $tags = self::string2array($tags_str);
     foreach ($tags as $one) {
         $tag_exists = Tag::find()->where("name = '" . $one . "'")->one();
         //var_dump($tag_exists); exit;
         if ($tag_exists == null) {
             $tag = new Tag();
             $tag->name = $one;
             $tag->frequency = 1;
             $tag->items .= $id;
             $tag->save();
         } else {
             if (array_search($id, self::string2array($tag_exists->items)) === false || array_search($id, self::string2array($tag_exists->items)) < 0) {
                 //var_dump($id);
                 //var_dump(self::string2array($tag_exists->items));
                 //var_dump(array_search($id, self::string2array($tag_exists->items)) === false);
                 //var_dump(array_search($id, self::string2array($tag_exists->items)) < 0); exit;
                 $tag_exists->frequency++;
                 $tag_exists->items .= "," . $id;
                 $tag_exists->update();
             }
         }
     }
 }
开发者ID:roman1970,项目名称:lis,代码行数:25,代码来源:Tag.php

示例5: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Seeds the tag table
     foreach (range(1, 1000) as $t) {
         $tag = new Tag();
         $tag->tag_name = str_shuffle('abcdefghijklmnopqrstuvwxyz');
         $tag->save();
     }
 }
开发者ID:RichNwankwo,项目名称:Gladysrepo,代码行数:14,代码来源:TagSeeder.php

示例6: saved

 public function saved($model)
 {
     foreach ($model->tags as $tag) {
         $new_tag = Tag::where('type', '=', $tag->type)->where('tag', '=', $tag->tag)->first();
         if (!$new_tag) {
             $new_tag = new Tag(['type' => $tag->type, 'tag' => $tag->tag]);
             $new_tag->save();
         }
     }
 }
开发者ID:erickmo,项目名称:CapcusAPI,代码行数:10,代码来源:EmbedTagsObserver.php

示例7: init

 public function init()
 {
     parent::init();
     $tag = new Tag();
     $tags = $tag->findTagWeights($this->max);
     foreach ($tags as $tag => $weight) {
         $link = Html::a(Html::encode($tag), ['post/index', 'tag' => $tag]);
         echo Html::tag('span', $link, ['class' => 'tag', 'style' => "font-size:{$weight}pt"]) . "\n";
     }
 }
开发者ID:rocketyang,项目名称:dcms2,代码行数:10,代码来源:TagCloud.php

示例8: addTags

 public function addTags($tags = [])
 {
     $rowTagsName = Tag::all(['name'])->toArray();
     $rowTagsName = array_flatten($rowTagsName);
     foreach ($tags as $key => $tag) {
         if (in_array($tag, $rowTagsName)) {
         } else {
             $tag = new Tag();
             $tag->name = $tag;
             $tag->save();
         }
     }
 }
开发者ID:limahfud,项目名称:skripsi,代码行数:13,代码来源:Product.php

示例9: edit

 public function edit($id)
 {
     $article = Article::findOrFail($id);
     //Calls for tag list
     $tags = Tag::lists('name', 'id');
     return view('articles.edit', compact('article', 'tags'));
 }
开发者ID:shep1990,项目名称:scorpio_studios,代码行数:7,代码来源:ArticleController.php

示例10: postUpload

 public function postUpload(Request $request)
 {
     $input = $request->all();
     $rules = array('image' => 'image|max:204800');
     $validation = \Validator::make($input, $rules);
     if ($validation->fails()) {
         return \Response::json([$validation->errors->first()], 400);
     }
     if ($media = $this->handleMediaUpload($request, 'image')) {
         $tagIDs = [];
         if ($request->has('tags')) {
             $tagList = explode(',', $request->input('tags'));
             foreach ($tagList as $tag) {
                 $tag = trim($tag);
                 $tagORM = \App\Models\Tag::where('name', $tag)->first() ?: new \App\Models\Tag();
                 $tagORM->name = $tag;
                 if (empty($tagORM->slug)) {
                     $tagORM->slug = \App\Helpers\Text::slugify($tagORM->name);
                 }
                 $tagORM->save();
                 $tagIDs[] = $tagORM->id;
             }
             if (count($tagIDs)) {
                 $media->tags()->sync($tagIDs);
             }
         }
         return \Response::json('success', 200);
     } else {
         return \Response::json('error', 400);
     }
 }
开发者ID:joshhudnall,项目名称:beancounter,代码行数:31,代码来源:AssetsController.php

示例11: generatePopular

 /**
  * Generate or regenerate popular Discover Cache items
  *
  * @param SearchHandlerInterface $searchHandler
  * @param CacheHandlerInterface $cacheHandler
  */
 public function generatePopular(SearchHandlerInterface $searchHandler, CacheHandlerInterface $cacheHandler)
 {
     $tags = Tag::all()->groupBy('name')->orderBy('created_at')->take(20)->get();
     foreach ($tags as $tag) {
         $this->generate($tag, $cacheHandler, $searchHandler);
     }
 }
开发者ID:brycenrogers,项目名称:linken,代码行数:13,代码来源:DiscoverCacheHandler.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         \App\Models\Tag::create(['name' => $faker->word]);
     }
 }
开发者ID:nbinkunwar,项目名称:laravel5_rest,代码行数:12,代码来源:TagsTableSeeder.php

示例13: delete

 public function delete()
 {
     $user = $this->auth();
     $tag = Tag::find(Input::get('tagId'));
     $tag->delete();
     return $this->output(new \stdClass());
 }
开发者ID:guodong,项目名称:wish-api,代码行数:7,代码来源:TagController.php

示例14: getTagWeights

 public static function getTagWeights($limit = 20)
 {
     $models = Tag::find()->with('posts')->orderBy('name')->all();
     $minFrequency = 0;
     $maxFrequency = 0;
     foreach ($models as $model) {
         $weight = count($model->posts);
         $minFrequency = $minFrequency > $weight ? $weight : $minFrequency;
         $maxFrequency = $maxFrequency < $weight ? $weight : $maxFrequency;
     }
     $sizeRange = self::MAX_FONT_SIZE - self::MIN_FONT_SIZE;
     $minCount = log($minFrequency + 1);
     $maxCount = log($maxFrequency + 1);
     if ($maxCount != $minCount) {
         $countRange = $maxCount - $minCount;
     } else {
         $countRange = 1;
     }
     $tags = [];
     foreach ($models as $model) {
         $tags[$model->name] = round(self::MIN_FONT_SIZE + (log(count($model->posts) + 1) - $minCount) * ($sizeRange / $countRange));
     }
     arsort($tags);
     return $tags;
 }
开发者ID:mamontovdmitriy,项目名称:aaaaa,代码行数:25,代码来源:Tag.php

示例15: composeSidebar

 /**
  * Compose the sidebar.
  */
 private function composeSidebar()
 {
     view()->composer('partials.sidebar', function ($view) {
         $view->with('latest', Article::published()->orderBy('id', 'desc')->take(5)->get());
         $view->with('tags', Tag::all());
     });
 }
开发者ID:mattvb91,项目名称:website-laravel,代码行数:10,代码来源:ViewComposerServiceProvider.php


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