{"id":19039627,"url":"https://github.com/windwalker-io/windwalker-model","last_synced_at":"2026-06-01T00:32:17.604Z","repository":{"id":21005515,"uuid":"24296125","full_name":"windwalker-io/windwalker-model","owner":"windwalker-io","description":"[READ ONLY][DEPRECATED] Subtree split of Windwalker Framework","archived":false,"fork":false,"pushed_at":"2016-04-02T05:34:12.000Z","size":8,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-10T23:29:01.549Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/ventoviro/windwalker","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/windwalker-io.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":"2014-09-21T16:21:41.000Z","updated_at":"2024-12-16T13:49:35.000Z","dependencies_parsed_at":"2022-07-26T15:02:05.211Z","dependency_job_id":null,"html_url":"https://github.com/windwalker-io/windwalker-model","commit_stats":null,"previous_names":["ventoviro/windwalker-model"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/windwalker-io/windwalker-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windwalker-io","download_url":"https://codeload.github.com/windwalker-io/windwalker-model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fwindwalker-model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27695653,"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","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-08T22:17:56.641Z","updated_at":"2025-12-12T23:56:31.738Z","avatar_url":"https://github.com/windwalker-io.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windwalker Model\n\nWindwalker Model provides an abstract interface to build your own model logic.\n\n## Installation via Composer\n\nAdd this to the require block in your `composer.json`.\n\n``` json\n{\n    \"require\": {\n        \"windwalker/model\": \"~2.0\"\n    }\n}\n```\n\n## Create Model\n\nExtends the AbstractModel to create your own model.\n\n``` php\nuse Windwalker\\Model\\AbstractModel\n\nclass MyModel extends AbstractModel\n{\n    public function getItem()\n    {\n        return new stdClass;\n    }\n}\n\n$model = new MyModel;\n\n$item = $model-\u003egetItem();\n```\n\n## Database Model\n\nImplements the `DatabaseModelInterface`, we will able to get and set a DB object to access database.\n\nWindwalker Model do not dependency to any Database package, you can integrate your favorite data source to get data.\n\n``` php\nuse Windwalker\\Model\\AbstractModel\nuse Windwalker\\Model\\DatabaseModelInterface;\n\nclass MyModel extends AbstractModel implements DatabaseModelInterface\n{\n    protected $db;\n\n    public function __construct($db, Registry $state = null)\n    {\n        $this-\u003edb = $db;\n\n        parent::__construct($state);\n    }\n\n    public function getDb()\n    {\n        return $this-\u003edb;\n    }\n\n    public function setDb($db)\n    {\n        $this-\u003edb = $db;\n    }\n\n    public function getList()\n    {\n        $this-\u003edb-\u003esetQuery('select * from users');\n\n        return $this-\u003edb-\u003eloadAll();\n    }\n}\n```\n\n## Model State\n\nModel maintains their own state that we can change this state to get different data.\n\n``` php\nclass MyModel extends AbstractModel implements DatabaseModelInterface\n{\n    // ...\n\n    public function getUsers()\n    {\n        $published = $this-\u003estate-\u003eget('where.published', 1);\n\n        $ordering  = $this-\u003estate-\u003eget('list.ordering', 'id');\n        $direction = $this-\u003estate-\u003eget('list.direction', 'ASC');\n\n        $sql = \"SELECT * FROM users \" .\n            \" WHERE published = \" . $published .\n            \" ORDER BY \" . $ordering . \" \" . $direction;\n\n        try\n        {\n            return $this-\u003edb-\u003esetQuery($sql)-\u003eloadAll();\n        }\n        catch (\\Exception $e)\n        {\n            $this-\u003estate-\u003eset('error', $e-\u003egetMessage());\n\n            return false;\n        }\n    }\n}\n\n$model = new MyModel;\n\n$state = $model-\u003egetState();\n\n// Let's change model state\n$state-\u003eset('where.published', 1);\n$state-\u003eset('list.ordering', 'birth');\n$state-\u003eset('list.direction', 'DESC');\n\n$users = $model-\u003egetUsers();\n\nif (!$users)\n{\n    $error = $state-\u003eget('error');\n}\n```\n\n### Simple Way to Access State\n\nUsing `get()` and `set()`\n\n``` php\n// Same as getState()-\u003eget();\n$model-\u003eget('where.author', 5);\n\n// Same as getState()-\u003eset();\n$model-\u003eset('list.ordering', 'RAND()');\n```\n\n### State ArrayAccess\n\n``` php\n// Same as getState()-\u003eget();\n$data = $model['list.ordering'];\n\n// Same as getState()-\u003eset();\n$model['list.ordering'] = 'created_time';\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fwindwalker-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindwalker-io%2Fwindwalker-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fwindwalker-model/lists"}