{"id":21437494,"url":"https://github.com/locustv2/yii2-json-data-behavior","last_synced_at":"2025-03-16T23:25:29.867Z","repository":{"id":62518704,"uuid":"86846370","full_name":"Locustv2/yii2-json-data-behavior","owner":"Locustv2","description":"Enables you to easily encode and decode json in your activerecords","archived":false,"fork":false,"pushed_at":"2017-03-31T19:16:55.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-24T16:54:42.171Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Locustv2.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":"2017-03-31T17:56:49.000Z","updated_at":"2017-03-31T19:24:27.000Z","dependencies_parsed_at":"2022-11-02T13:45:52.502Z","dependency_job_id":null,"html_url":"https://github.com/Locustv2/yii2-json-data-behavior","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Locustv2%2Fyii2-json-data-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Locustv2%2Fyii2-json-data-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Locustv2%2Fyii2-json-data-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Locustv2%2Fyii2-json-data-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Locustv2","download_url":"https://codeload.github.com/Locustv2/yii2-json-data-behavior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243946328,"owners_count":20373029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-23T00:20:20.342Z","updated_at":"2025-03-16T23:25:29.845Z","avatar_url":"https://github.com/Locustv2.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonData behavior for Yii2 ActiveRecords\nEnables you to easily encode and decode json in your activerecords. It automatically encodes before validating and saving to database and decodes after.\n\n[![Latest Stable Version](https://poser.pugx.org/Locustv2/yii2-json-data-behavior/v/stable)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)\n[![Total Downloads](https://poser.pugx.org/Locustv2/yii2-json-data-behavior/downloads)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)\n[![Latest Unstable Version](https://poser.pugx.org/Locustv2/yii2-json-data-behavior/v/unstable)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)\n[![License](https://poser.pugx.org/Locustv2/yii2-json-data-behavior/license)](https://packagist.org/packages/Locustv2/yii2-json-data-behavior)\n\n\n## Installation\n\nThe preferred way to install the library is through [composer](https://getcomposer.org/download/).\n\nEither run\n```\nphp composer.phar require --prefer-dist locustv2/yii2-json-data-behavior\n```\n\nor add\n```json\n{\n    \"require\": {\n        \"locustv2/yii2-json-data-behavior\": \"~1.0.0\"\n    }\n}\n```\nto your `composer.json` file.\n\n## Usage\n\n```php\npublic function behaviors()\n{\n    return [\n        'class' =\u003e \\locustv2\\behaviors\\JsonDataBehavior::className(),\n        'dataAttribute' =\u003e 'hotel_data',\n    ];\n}\n```\nAfter configuring your activerecord as above, you can use as follows:\n```php\n$model = Hotel::find()-\u003eone();\n\nvar_dump($model-\u003egetData('rooms')); // assume it returns a list of rooms\nvar_dump($model-\u003egetData('rooms.0.price')); // to get rooms data\n\n$model-\u003esetData('ratings', [\n    '5star' =\u003e ['count' =\u003e 100],\n    '4star' =\u003e ['count' =\u003e 200],\n    '3star' =\u003e ['count' =\u003e 20],\n    '2star' =\u003e ['count' =\u003e 75],\n    '1star' =\u003e ['count' =\u003e 50],\n]);\n\nvar_dump($model-\u003egetData('ratings.3star.count')); // returns 20\n```\n\n\n## To do\n - Add unit tests\n\n## Contributing\nFeel free to send pull requests.\n\n\n## License\nFor license information check the [LICENSE](LICENSE.md)-file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocustv2%2Fyii2-json-data-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocustv2%2Fyii2-json-data-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocustv2%2Fyii2-json-data-behavior/lists"}