{"id":39810880,"url":"https://github.com/rkit/tags-behavior-yii2","last_synced_at":"2026-01-18T12:44:02.390Z","repository":{"id":62536205,"uuid":"140735428","full_name":"rkit/tags-behavior-yii2","owner":"rkit","description":"Tags Behavior for Yii2","archived":false,"fork":false,"pushed_at":"2018-08-07T16:19:27.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-19T06:44:22.070Z","etag":null,"topics":["tags","yii2"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-12T15:58:15.000Z","updated_at":"2018-08-07T16:19:28.000Z","dependencies_parsed_at":"2022-11-02T15:01:22.822Z","dependency_job_id":null,"html_url":"https://github.com/rkit/tags-behavior-yii2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/rkit/tags-behavior-yii2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkit%2Ftags-behavior-yii2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkit%2Ftags-behavior-yii2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkit%2Ftags-behavior-yii2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkit%2Ftags-behavior-yii2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rkit","download_url":"https://codeload.github.com/rkit/tags-behavior-yii2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rkit%2Ftags-behavior-yii2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["tags","yii2"],"created_at":"2026-01-18T12:44:01.586Z","updated_at":"2026-01-18T12:44:02.355Z","avatar_url":"https://github.com/rkit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tags Behavior for Yii2\n\n[![Build Status](https://travis-ci.org/rkit/tags-behavior-yii2.svg?branch=master)](https://travis-ci.org/rkit/tags-behavior-yii2)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rkit/tags-behavior-yii2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rkit/tags-behavior-yii2/?branch=master)\n\nFlexible yii2 behavior for tags.\n\n## Requirements\n\nPHP 7\n\n## Installation\n\n```\ncomposer require rkit/tags-behavior-yii2\n```\n\n## Configuration\n\nFor example, we have a `Post` model and we want to add tags.  \nLet's do it.\n\n1. Add `tag` and `post_to_tag` tables and a `Tag` model for the tags\n\n```php\n$this-\u003ecreateTable('{{%tag}}', [\n    'id' =\u003e $this-\u003eprimaryKey(),\n    'name' =\u003e $this-\u003estring()-\u003enotNull()-\u003eunique(),\n    'frequency' =\u003e $this-\u003einteger()-\u003enotNull()-\u003edefaultValue(0),\n]);\n\n$this-\u003ecreateTable('{{%post_to_tag}}', [\n    'post_id' =\u003e $this-\u003einteger()-\u003enotNull()-\u003edefaultValue(0),\n    'tag_id' =\u003e $this-\u003einteger()-\u003enotNull()-\u003edefaultValue(0),\n]);\n\n$this-\u003eaddPrimaryKey('', '{{%post_to_tag}}', ['post_id', 'tag_id']);\n```\n\n2. Add a `TagsBehavior` behavior to the `Post` model\n\n```php\npublic function behaviors()\n{\n    return [\n        'tagsBehavior' =\u003e [\n            'class' =\u003e 'rkit\\tags\\behavior\\TagsBehavior',\n            'relation' =\u003e 'tags',\n            'tagAttribute' =\u003e 'name',\n            'tagFrequencyAttribute' =\u003e 'frequency', // or false\n            'findTag' =\u003e function ($value) {\n                return Tag::find()-\u003ewhere([$this-\u003etagAttribute =\u003e $value])-\u003eone();\n            },\n            'createTag' =\u003e function ($value) {\n                $tag = new Tag();\n                $tag-\u003e{$this-\u003etagAttribute} = $value;\n                return $tag;\n            },\n        ],\n    ];\n}\n```\n\n3. Add a `tags` relation (see `relation` option in the behavior)\n\n```php\n/**\n * @return \\yii\\db\\ActiveQuery\n */\npublic function getTags()\n{\n    return $this\n        -\u003ehasMany(Tag::class, ['id' =\u003e 'tag_id'])\n        -\u003eviaTable('{{%post_to_tag}}', ['post_id' =\u003e 'id']);\n}\n```\n\n## Usage\n\n### Add tags\n\n```php\n$model = new Post();\n$model-\u003esetTagValues(['example1', 'example2']);\n$model-\u003esave();\n```\n\n### Get tags\n\n```php\n$post = Post::find()-\u003ewith('tags')-\u003ewhere(['id' =\u003e $id])-\u003eone();\n$post-\u003egetTagValues();\n```\n\n### Remove tags\n\n```php\n$model = new Post();\n$model-\u003esetTagValues([]);\n$model-\u003esave();\n```\n\n## Tests\n\n- [See docs](/tests/#tests)\n\n## Coding Standard\n\n- PHP Code Sniffer ([phpcs.xml](./phpcs.xml))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frkit%2Ftags-behavior-yii2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frkit%2Ftags-behavior-yii2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frkit%2Ftags-behavior-yii2/lists"}