{"id":20262722,"url":"https://github.com/jcsama/codeigniter-model","last_synced_at":"2026-03-05T17:42:54.862Z","repository":{"id":35133975,"uuid":"39341969","full_name":"JCSama/CodeIgniter-Model","owner":"JCSama","description":"CodeIgniter Model is an extended class for CI_Model, it allows you to manipulate CRUD operations in an easy way. It support multilang and relations between tables.","archived":false,"fork":false,"pushed_at":"2015-08-03T15:18:10.000Z","size":616,"stargazers_count":5,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-25T18:43:57.615Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/JCSama.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-19T17:16:56.000Z","updated_at":"2018-09-07T02:55:37.000Z","dependencies_parsed_at":"2022-08-17T21:35:04.639Z","dependency_job_id":null,"html_url":"https://github.com/JCSama/CodeIgniter-Model","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/JCSama/CodeIgniter-Model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCSama%2FCodeIgniter-Model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCSama%2FCodeIgniter-Model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCSama%2FCodeIgniter-Model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCSama%2FCodeIgniter-Model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JCSama","download_url":"https://codeload.github.com/JCSama/CodeIgniter-Model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JCSama%2FCodeIgniter-Model/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30139445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T16:58:46.102Z","status":"ssl_error","status_checked_at":"2026-03-05T16:58:45.706Z","response_time":93,"last_error":"SSL_read: 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":[],"created_at":"2024-11-14T11:31:22.753Z","updated_at":"2026-03-05T17:42:54.818Z","avatar_url":"https://github.com/JCSama.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeIgniter Model Class\n\nCodeIgniter Model is an extended class for CI_Model, it will help you to :\n\n- CRUD operations.\n- Auto-save for multilang tables.\n- Fetch data using associations like oneToMany, ManyToOne\n- Apply filters to results\n- Pagination...\n\n# Installation\n\nCodeIgniter Versoin \u003e= 2.x.x\n\n\nCopy the file `MY_Model.php` to the `application/core/` folder.\n\n# Usage\n\nCreate a Model that extends from MY_Model and set the variables :\n\n```php\nprotected $table = 'my_table';\n\nprotected $identifier = 'id_my_table';\n\nprotected $foreign_key = 'my_table_id';\n\nprotected $fields = array(\n    'field_1',\n    'field_2',\n);\n```\n# Example\nAssuming that we have 2 tables advertisement and category, each advertisement belongs to a category, so a category can have\none or many advertisements, which means our tables may look like this :\n\nNOTES :\n  - The category table has multilang fields so we're gonna put them in category_lang table\n  - {table}_lang must respect the recommended structure\n\n -----------------------\n| category              |\n -----------------------\n| id_category (int)     |\n| parent (int)          |\n| created_at (datetime) |\n| updated_at (datetime) |\n -----------------------\n -----------------------\n| category_lang         |\n -----------------------\n| category_id (int)     |\n| lang_id (int)         |\n| title (varchar)       |\n| description (varchar) |\n -----------------------\n -----------------------\n| advert                |\n -----------------------\n| id_advert (int)       |\n| category_id (int)     |\n| title (int)           |\n| description (int)     |\n| deleted (tinyInt)     |\n| created_at (datetime) |\n| updated_at (datetime) |\n -----------------------\n\n## Fetch records\nAfter that, you can call the Model within your controller for instance like following :\n\n```php\n// Fetch all records\n$this-\u003eload-\u003emodel('New_model');\n$records = $this-\u003eNew_model-\u003eget_all();\nvar_dump($records);\n\n// Return record with id=10\n$record = $this-\u003eNew_model-\u003eget(10);\nvar_dump($record);\n```\n\n## Fetch records with criteria\n```php\n// You can also add some criteria like following :\n$criteria = array();\n$criteria[] = array('title', 'like', 'test');\n$criteria[] = array('id_my_table', '=', 10);\n\n$result = $this-\u003eNew_model-\u003eget_all($criteria);\n                \nvar_dump($result);\n```\n\n## Fetch record with association\n```php\n$result = $this-\u003eAdvert_model\n                -\u003ewith('category')\n                -\u003eorder_by('created_at', 'DESC')\n                -\u003eget_all($criteria);\n                \nvar_dump($result);\n\n$result = $this-\u003eCategory_model\n                -\u003ewith('advert')\n                -\u003eget_all();\n                \nvar_dump($result);\n```\n\n## Fetch records with multiple associations\n```php\n$result = $this-\u003eAdvert_model\n                -\u003ewith('category')\n                -\u003ewith('alias_2')\n                -\u003ewith('alias_3')\n                -\u003eorder_by('created_at', 'DESC')\n                -\u003eget_all($criteria);\n                \nvar_dump($result);\n```\n\n## Fetch records with filter on the associations\n```php\n$filter = array();\n$filter[] = array('lang_id', '=', 2);\n$result = $this-\u003eAdvert_model\n                -\u003ewith('category', $filter)\n                -\u003ewith('alias_2')\n                -\u003ewith('alias_3')\n                -\u003eorder_by('created_at', 'DESC')\n                -\u003eget_all($criteria);\n                \nvar_dump($result);\n```\n\n## Fetch records with pagination\n```php\n$page = 1;\n$total_items_per_page = 100;\n$records = $this-\u003eAdvert_model\n                -\u003elimit($total_items_per_page, $page)\n                -\u003eorder_by('created_at', 'DESC')\n                -\u003eget_all($criteria);\n\n$total_records = $this-\u003eAdvert_model-\u003ecount_all_results();\nvar_dump($records);\n```\n\n## Add new record\n```php\n$data = array(\n  'title' =\u003e 'New Advertisement',\n  'description' =\u003e 'New Advertisement',\n  'deleted' =\u003e 0,\n  'category_id' =\u003e 23,\n);\n$this-\u003eAdvert_model-\u003esave($data);\n```\n\n## Update record\n```php\n$id_record = 10;\n$data = array(\n  'title' =\u003e 'Update Advertisement',\n  'description' =\u003e 'Update Advertisement',\n  'deleted' =\u003e 0,\n  'category_id' =\u003e 23,\n);\n$this-\u003eAdvert_model-\u003esave($data, $id_record);\n```\n\n## Delete record\n```php\n$id_record = 10;\n$this-\u003eAdvert_model-\u003edelete($id_record);\n```\n\n## Check if a record exists\n```php\n$exists = $this-\u003eAdvert_model-\u003eexists('id_advert', 10);\n\n// $exists = true : if the record exists, and false if not\n\n// Check if an email address exists but the user id must NOT be mine \n$exclude_condition = array('id_user' =\u003e $this-\u003elogged_user-\u003eget_id());\n$exists = $this-\u003eUser_model-\u003eexists('email', 'example@email.com', $exclude_condition);\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcsama%2Fcodeigniter-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcsama%2Fcodeigniter-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcsama%2Fcodeigniter-model/lists"}