@@ -20,7 +20,7 @@ $ composer require creocoder/yii2-taggable
2020or add
2121
2222```
23- "creocoder/yii2-taggable": "~1 .0"
23+ "creocoder/yii2-taggable": "~2 .0"
2424```
2525
2626to the ` require ` section of your ` composer.json ` file.
@@ -88,7 +88,7 @@ use creocoder\taggable\TaggableBehavior;
8888
8989/**
9090 * ...
91- * @property string $tagNames
91+ * @property string $tagValues
9292 */
9393class Post extends \yii\db\ActiveRecord
9494{
@@ -97,9 +97,9 @@ class Post extends \yii\db\ActiveRecord
9797 return [
9898 'taggable' => [
9999 'class' => TaggableBehavior::className(),
100- // 'tagNamesAsArray ' => false,
100+ // 'tagValuesAsArray ' => false,
101101 // 'tagRelation' => 'tags',
102- // 'tagNameAttribute ' => 'name',
102+ // 'tagValueAttribute ' => 'name',
103103 // 'tagFrequencyAttribute' => 'frequency',
104104 ],
105105 ];
@@ -109,7 +109,7 @@ class Post extends \yii\db\ActiveRecord
109109 {
110110 return [
111111 //...
112- ['tagNames ', 'safe'],
112+ ['tagValues ', 'safe'],
113113 ];
114114 }
115115
@@ -161,10 +161,10 @@ To set tags to the entity
161161$post = new Post();
162162
163163// through string
164- $post->tagNames = 'foo, bar, baz';
164+ $post->tagValues = 'foo, bar, baz';
165165
166166// through array
167- $post->tagNames = ['foo', 'bar', 'baz'];
167+ $post->tagValues = ['foo', 'bar', 'baz'];
168168```
169169
170170### Adding tags to the entity
@@ -175,10 +175,10 @@ To add tags to the entity
175175$post = Post::findOne(1);
176176
177177// through string
178- $post->addTagNames ('bar, baz');
178+ $post->addTagValues ('bar, baz');
179179
180180// through array
181- $post->addTagNames (['bar', 'baz']);
181+ $post->addTagValues (['bar', 'baz']);
182182```
183183
184184### Remove tags from the entity
@@ -189,10 +189,19 @@ To remove tags from the entity
189189$post = Post::findOne(1);
190190
191191// through string
192- $post->removeTagNames ('bar, baz');
192+ $post->removeTagValues ('bar, baz');
193193
194194// through array
195- $post->removeTagNames(['bar', 'baz']);
195+ $post->removeTagValues(['bar', 'baz']);
196+ ```
197+
198+ ### Remove all tags from the entity
199+
200+ To remove all tags from the entity
201+
202+ ``` php
203+ $post = Post::findOne(1);
204+ $post->removeAllTagValues();
196205```
197206
198207### Getting tags from the entity
@@ -204,14 +213,14 @@ $posts = Post::find()->with('tags')->all();
204213
205214foreach ($posts as $post) {
206215 // as string
207- $tagNames = $post->tagNames ;
216+ $tagValues = $post->tagValues ;
208217
209218 // as array
210- $tagNamesAsArray = $post->getTagNames (true);
219+ $tagValuesAsArray = $post->getTagValues (true);
211220}
212221```
213222
214- Return type of ` getTagNames ` can also be configured globally via ` tagNamesAsArray ` property.
223+ Return type of ` getTagValues ` can also be configured globally via ` tagValuesAsArray ` property.
215224
216225### Checking for tags in the entity
217226
@@ -221,10 +230,10 @@ To check for tags in the entity
221230$post = Post::findOne(1);
222231
223232// through string
224- $result = $post->hasTagNames ('foo, bar');
233+ $result = $post->hasTagValues ('foo, bar');
225234
226235// through array
227- $result = $post->hasTagNames (['foo', 'bar']);
236+ $result = $post->hasTagValues (['foo', 'bar']);
228237```
229238
230239### Search entities by any tags
@@ -233,10 +242,20 @@ To search entities by any tags
233242
234243``` php
235244// through string
236- $posts = Post::find()->anyTagNames('foo, bar')->all();
245+ $posts = Post::find()->anyTagValues('foo, bar')->all();
246+
247+ // through array
248+ $posts = Post::find()->anyTagValues(['foo', 'bar'])->all();
249+ ```
250+
251+ To search entities by any tags using custom tag model attribute
252+
253+ ``` php
254+ // through string
255+ $posts = Post::find()->anyTagValues('foo-slug, bar-slug', 'slug')->all();
237256
238257// through array
239- $posts = Post::find()->anyTagNames (['foo', 'bar'] )->all();
258+ $posts = Post::find()->anyTagValues (['foo-slug ', 'bar-slug'], 'slug' )->all();
240259```
241260
242261### Search entities by all tags
@@ -245,10 +264,20 @@ To search entities by all tags
245264
246265``` php
247266// through string
248- $posts = Post::find()->allTagNames ('foo, bar')->all();
267+ $posts = Post::find()->allTagValues ('foo, bar')->all();
249268
250269// through array
251- $posts = Post::find()->allTagNames(['foo', 'bar'])->all();
270+ $posts = Post::find()->allTagValues(['foo', 'bar'])->all();
271+ ```
272+
273+ To search entities by all tags using custom tag model attribute
274+
275+ ``` php
276+ // through string
277+ $posts = Post::find()->allTagValues('foo-slug, bar-slug', 'slug')->all();
278+
279+ // through array
280+ $posts = Post::find()->allTagValues(['foo-slug', 'bar-slug'], 'slug')->all();
252281```
253282
254283### Search entities related by tags
@@ -257,10 +286,20 @@ To search entities related by tags
257286
258287``` php
259288// through string
260- $posts = Post::find()->relatedByTagNames('foo, bar')->all();
289+ $posts = Post::find()->relatedByTagValues('foo, bar')->all();
290+
291+ // through array
292+ $posts = Post::find()->relatedByTagValues(['foo', 'bar'])->all();
293+ ```
294+
295+ To search entities related by tags using custom tag model attribute
296+
297+ ``` php
298+ // through string
299+ $posts = Post::find()->relatedByTagValues('foo-slug, bar-slug', 'slug')->all();
261300
262301// through array
263- $posts = Post::find()->relatedByTagNames (['foo', 'bar'] )->all();
302+ $posts = Post::find()->relatedByTagValues (['foo-slug ', 'bar-slug'], 'slug' )->all();
264303```
265304
266305## Donating
0 commit comments