{"id":20963869,"url":"https://github.com/codemix/yiiabstractarraymodel","last_synced_at":"2026-04-20T21:37:33.999Z","repository":{"id":12160983,"uuid":"14756574","full_name":"codemix/YiiAbstractArrayModel","owner":"codemix","description":"Work with PHP files in Active Record way","archived":false,"fork":false,"pushed_at":"2013-11-27T22:00:54.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-20T01:34:47.938Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codemix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-27T19:16:22.000Z","updated_at":"2013-12-05T13:32:45.000Z","dependencies_parsed_at":"2022-09-05T20:21:16.546Z","dependency_job_id":null,"html_url":"https://github.com/codemix/YiiAbstractArrayModel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2FYiiAbstractArrayModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2FYiiAbstractArrayModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2FYiiAbstractArrayModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2FYiiAbstractArrayModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemix","download_url":"https://codeload.github.com/codemix/YiiAbstractArrayModel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243360342,"owners_count":20278365,"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-19T02:48:41.676Z","updated_at":"2025-12-28T21:20:18.606Z","avatar_url":"https://github.com/codemix.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"YiiAbstractArrayModel\n=====================\n\nWork with PHP files in an Yii Active Record way.\n\nWhenever there is a bunch of PHP array files that need to be maintained through a web interface, one could do CRUD operations by extending the AbstractArrayModel class.\n\n\n##Usage\n\nSupposing we need to manage the following config files:\n\n\n\u003cb\u003e/path/to/config/\u003c/b\u003e\n\u003cpre\u003e\nconfig1.php\nconfig2.php\nconfig3.php\nold-config1.php\n...\n\u003c/pre\u003e\n\n\u003cb\u003econfig1.php\u003c/b\u003e\n\u003cpre\u003e\n return array(\n     'name' =\u003e 'site',\n     'theme' =\u003e 'bootstrap',\n     'components' =\u003e array(\n         'bill' =\u003e array(\n             'siteId' =\u003e 11,\n             'packages' =\u003e array(\n                 8001,   \n                 10442\n             ),  \n         ),\n     ),\n     'params' =\u003e array(\n         'mainCssUrl' =\u003e '/css/app/site.css',\n         'prefix' =\u003e 'M',\n     )   \n );  \n\u003c/pre\u003e\n\n\n\nWe define our model by extending the AbstractArrayModel class and overriding the following methods:\n\u003cpre\u003e\nclass Config extends AbstractArrayModel\n{\n\n    /**\n     * Base path definition\n     * @return string base path\n     */\n    public function getBasePath(){\n        return '/path/to/config/';\n    }\n\n    /**\n     * File pattern matching\n     * @return string pattern\n     */\n    public function getPattern(){\n        return '*.php';\n    }\n\n    /**\n     * @return array validation rules for model attributes.\n     */\n    public function rules()\n    {\n        // NOTE: you should only define rules for those attributes that\n        // will receive user inputs.\n        return array(\n            // The following rule is used by search().\n            // Please remove those attributes that should not be searched.\n            array('name, theme, components, params', 'safe'),\n        );\n    }   \n\n    /**\n     * Returns the list of all attribute names of the model.\n     * @return array list of attribute names.\n     */\n    public function attributeNames()\n    {\n        return array('name', 'theme', 'components', 'params');\n    }\n}\n\u003c/pre\u003e\n\nFollowing methods are now available:\n\u003cpre\u003e\n$model = Config::model()-\u003efindByPk('config1');\n$model-\u003etheme = 'foundation'; \n$model-\u003ecomponents['bill']['siteId'] = 99; \n$model-\u003esave(); //save the file\n\n$model-\u003edelete(); //remove the file\n\n$models = Config::model()-\u003efindAll(); // returns all files as models\n\n//We can also pattern match the name. Internally uses the PHP [glob] (http://php.net/manual/en/function.glob.php) method \n$model = Config::model()-\u003efindA('old-*');\n$models = Config::model()-\u003efindAll('config*');\n\n\u003c/pre\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fyiiabstractarraymodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemix%2Fyiiabstractarraymodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fyiiabstractarraymodel/lists"}