{"id":26117140,"url":"https://github.com/eskylake/poler","last_synced_at":"2025-08-11T15:24:49.178Z","repository":{"id":78252633,"uuid":"199740131","full_name":"eskylake/poler","owner":"eskylake","description":"A simple PHP model-view-controller (MVC) framework","archived":false,"fork":false,"pushed_at":"2019-08-02T19:07:19.000Z","size":80,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T08:51:17.288Z","etag":null,"topics":["framework","mvc","php"],"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/eskylake.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-30T23:06:17.000Z","updated_at":"2024-05-13T07:30:02.000Z","dependencies_parsed_at":"2023-04-21T08:17:19.666Z","dependency_job_id":null,"html_url":"https://github.com/eskylake/poler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eskylake/poler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eskylake%2Fpoler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eskylake%2Fpoler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eskylake%2Fpoler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eskylake%2Fpoler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eskylake","download_url":"https://codeload.github.com/eskylake/poler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eskylake%2Fpoler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269912001,"owners_count":24495245,"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-08-11T02:00:10.019Z","response_time":75,"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":["framework","mvc","php"],"created_at":"2025-03-10T10:58:43.610Z","updated_at":"2025-08-11T15:24:49.170Z","avatar_url":"https://github.com/eskylake.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poler\n\nThis is a simple PHP model-view-controller (MVC) framework with user authentication.\n\n## Installation\n\nDownload or clone the project:\n\n```git\ngit clone git@github.com:Tavafi/poler.git\n```\n\nInstructs composer to create autoloader:\n\n```composer\ncomposer dump-autoload\n```\nImport `User.sql` into your database:\n```mysql\nmysql -u root -p -h localhost YourDataBase \u003c User.sql\n```\nAll of the environment variable options are in `env.php.example` file.\nCopy `env.php.example` to `env.php`:\n```bash\ncp env.php.example env.php\n```\nYou can add additional options to `$variables` array as you want. Edit `DB_` values in order to connecting to database:\n\n```php\n'DB_HOST' =\u003e 'localhost',\n'DB_USERNAME' =\u003e 'DBUser',\n'DB_PASSWORD' =\u003e 'DBPass',\n'DB_NAME' =\u003e 'DBName',\n'DB_PORT' =\u003e '3306',\n```\nDefault database host address is `localhost`. Modify it to another host if you want.\n\nNow you can access variables globally in your code using `env()` function. For example:\n```php\n$dbHost = env('DB_HOST');\n```\n## Usage\n### Initialization\n\nConfigure your web server's document / web root to be the  `public` directory. The `index.php` in this directory serves as the front controller for all HTTP requests entering your application.\nThe main directory of the application is `app` with predefined structure.\n```bash\napp\n├── controllers\n│   ├── HomeController.php\n│   └── UserController.php\n├── core\n│   ├── Autoload.php\n│   ├── Controller.php\n│   ├── DB.php\n│   ├── Model.php\n│   ├── Path.php\n│   └── TokenGenerator.php\n├── interfaces\n│   └── DatabaseRepository.php\n├── models\n│   └── User.php\n├── repositories\n│   └── DatabaseRepository.php\n└── views\n    ├── home\n    │   └── index.php\n    ├── layouts\n    │   ├── Main.php\n    │   └── User.php\n    └── user\n        ├── login.php\n        └── register.php\n```\n\n## Models\nCreate your model classes in `models/` directory. You must inherit from `\\App\\core\\Model` base class in order to validate or sanitize data, connect to database etc.\n\nFor example:\n```php\n\u003c?php\nnamespace App\\models;\n\nuse App\\core\\Model;\n\nclass Example extends Model\n{\n\n}\n```\nIf your model connects to specific table, modify `$table` property of the class to its name.\n```php\nprotected $table = \"example\";\n```\n\n### Validation rules\nThere are some predefined validation rules in the base model class that are listed below. You can add additional types as you want.\n\n| Rules         | Definition                                            | \n|:-------------:|:-----------------------------------------------------:|\n| **string**    | Data type is string. Value length \u003c= 255 characters   |\n| **integer**   | Data type is integer and unsigned                     |\n| **text**      | Data type is string. Value length \u003c= 65535 characters |\n| **required**  | Value is not null or empty                            |\n| **unique**    | Value is unique in model's table                      |\n\n#### Usage\nAll you need is to define the `rules()` method in your model class that it has to return an array of rules. Each key of this array specifies the rule name that it contains an array of attributes to be validated.\n\n\nFor example the example class has three attributes, username, password and age:\n```php\nclass Example extends Model\n{\n    protected $table = \"example\";\n\n    public function rules(): array\n    {\n        return [\n            'string' =\u003e [\n                'username',\n                'password'\n            ],\n            'required' =\u003e [\n                'username',\n                'password'\n            ],\n            'integer' =\u003e ['age']\n        ];\n    }\n}\n```\n## Views\nCreate your own view files under the `views/` directory. It is better to have separated directories for each of your controller classes, but there is no compulsion for this. All you have to do is that to create a `.php` file, e.g. `example.php`, with specific namespace and all the rest of your front codes.\n\nFor example we need a view file for our example class, we create the `example.php` file under the `example` directory:\n```bash\napp/views\n└── example\n    └── example.php\n```\nIt looks like:\n```php\n\u003c?php\nnamespace App\\views\\example;\n?\u003e\n\nAll of the front codes must be written here :)\n```\n#### Layouts\nBased on [Yii 2.0 definition](https://www.yiiframework.com/doc/guide/2.0/en/structure-views#layouts \"Yii 2.0 Layouts\"), layouts are a special type of views that represent the common parts of multiple views. For example, the pages for most Web applications share the same page header and footer. While you can repeat the same page header and footer in every view, a better way is to do this once in a layout and embed the rendering result of a content view at an appropriate place in the layout.\n\nCreating layouts is similar to views, but they have to be created under `views/layouts/` directory.\n\nFor example:\n```bash\napp/views\n└── layouts\n    └── Example.php\n```\nIt looks like:\n```php\n\u003c?php\nnamespace App\\views\\layouts;\n?\u003e\n\nAll of the front codes must be written here :)\n```\n## Controllers\nCreate your controller classes in `controllers/` directory. You must inherit from `\\App\\core\\Controller` base class that it contains some useful methods such as `redirect()` and `render()`.\n\nThere are two steps needed to create a controller:\n1. Choose a name for your class :) e.g. `Example`\n2. Concatenate it with `Controller` keyword\n\n\nNow we have `ExampleController` class. It looks like:\n```php\n\u003c?php\nnamespace App\\controllers;\n\nuse App\\core\\Controller;\n\nclass ExampleController extends Controller\n{\n    protected $layout = 'Example';\n}\n```\nAs you can see you can specify which layout must be loaded for all methods inside the controller by defining `$layout` property.\n\nThere are two useful methods that you can call in your controllers, `redirect()` and `render()`:\n\n#### redirect()\nThis method redirects to a specific URL route. All you have to do is that to pass the route as the first argument of this method.\n\nFor example in our example class we have an index method that redirects to `/home/index`:\n```php\npublic function index()\n{\n    $this-\u003eredirect('/home/index');\n}\n```\n#### render()\nThis method renders a specific view. It accepts two parameters:\n1. View file name\n2. Array of data you need in the view\n\nFor example in our example class we have a hello method that renders `example/hello.php` view file with 'Hello World' message:\n```php\npublic function hello()\n{\n    $this-\u003erender('example/hello', [\n        'message' =\u003e 'Hello World'\n    ]);\n}\n```\nIt will fill the `$data` variable with the array you have passed to the view. Now you can access to the `message` just like this:\n```php\n\u003c?= $data['message'] ?\u003e\n```\n## Queries\nThere are some simple query methods that you have access into your models if your model extends `\\App\\core\\Model` base class.\n\n#### create()\nThis method creates new record with specific data passed as the first argument to this method. For example:\n```php\n(new \\App\\models\\Example)-\u003ecreate([\n    'username' =\u003e 'AliTavafi',\n    'password' =\u003e 'passwordHash',\n    'age' =\u003e 21\n]);\n```\n#### select()\nThis method select all or specific columns from the table. You can pass the array of columns you want as the first argument.\n\n#### one()\nThis method returns only one record.\n\n#### all()\nThis method returns all records.\n\nFor example:\n```php\n(new \\App\\models\\Example)-\u003eselect()\n    -\u003eone();\n// or specific columns\n(new \\App\\models\\Example)-\u003eselect(['username', 'age'])\n    -\u003eone();\n```\nOr\n```php\n(new \\App\\models\\Example)-\u003eselect()\n    -\u003eall();\n// or specific columns\n(new \\App\\models\\Example)-\u003eselect(['username', 'age'])\n    -\u003eall();\n```\n#### where()\nThis method apply conditions to the query. It has three main parameters:\n```php\n-\u003ewhere(column, operator, value);\n```\nFor example:\n```php\n(new \\App\\models\\Example)-\u003ewhere('username', '=', 'AliTavafi')\n    -\u003ewhere('age', '=', 21)\n    -\u003eselect()\n    -\u003eone();\n```\nIt will return the first record of the example table with 'AliTavafi' username.\n\n#### update()\nThis method updates a record with specific data. It accepts an array of `column =\u003e value` that updates table's column with the value. For example:\n```php\n(new \\App\\models\\Example)-\u003ewhere('username', '=', 'AliTavafi')\n    -\u003eupdate([\n        'username' =\u003e 'Tavafi',\n        'password' =\u003e 'newPasswordHash'\n    ]);\n```\n#### orderBy()\nThis methods sorts the query result based on a column and an order type.\n\nOrder types:\n1. ASC (default type that means ascending)\n2. DESC (descending)\n\nIt has two main parameters:\n```php\n-\u003eorderBy(column, 'ASC' or 'DESC');\n```\nFor example:\n```php\n(new \\App\\models\\Example)-\u003ewhere('age', '\u003e=', 20)\n    -\u003eorderBy('id', 'DESC')\n    -\u003eselect()\n    -\u003eall();\n```\n\n#### getByColumn()\nThis method returns only one record with specific condition. It has three main parameters:\n```php\n-\u003egetByColumn(column, value, order type); // Default order type is 'ASC'\n```\n\nFor example:\n```php\n(new \\App\\models\\Example)-\u003egetByColumn('age', 21, 'DESC');\n```\nIt will sort the records descending and return the first record with age 21.\n\n#### getAllByColumn()\nThis method returns all records with specific condition. It has three main parameters:\n```php\n-\u003egetAllByColumn(column, value, order type); // Default order type is 'ASC'\n```\n\nFor example:\n```php\n(new \\App\\models\\Example)-\u003egetAllByColumn('age', 21, 'DESC');\n```\nIt will sort the records descending and return all records with age 21.\n\n## Feedback\nAll bugs, feature requests, pull requests, feedback, etc., are welcome. [Create an issue](https://github.com/Tavafi/poler/issues).\n\n## License\n[MIT](https://github.com/Tavafi/poler/blob/master/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feskylake%2Fpoler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feskylake%2Fpoler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feskylake%2Fpoler/lists"}