|
3 | 3 | [](https://codeclimate.com/github/mcred/phpred)
|
4 | 4 | [](https://codeclimate.com/github/mcred/phpred/coverage)
|
5 | 5 | [](https://codeclimate.com/github/mcred/phpred)
|
| 6 | + |
| 7 | +### Description |
| 8 | +<p>PHPRed is an opinionated light weight ORM. While there are many available ORMs for PHP, many contain features that I have never used. PHPRed contains very basic methods and usage.</p> |
| 9 | + |
| 10 | +### Requirements |
| 11 | +* PHP 7.1+ |
| 12 | +* Composer |
| 13 | +* Mysqli |
| 14 | + |
| 15 | +### Installation |
| 16 | + |
| 17 | +``` |
| 18 | +composer require mcred/phpred |
| 19 | +``` |
| 20 | + |
| 21 | +### Setup |
| 22 | +<p>In addition to the example below, there are examples available in the `tests/mocks` folder. Setting up a model is very easy: create a model class that extends the `PHPRed/Models/Model` class then define the properties of that model in the constructor. Such as: </p> |
| 23 | + |
| 24 | +```php |
| 25 | +<?php |
| 26 | +class MyClass extends PHPRed\Models\Model |
| 27 | +{ |
| 28 | + public function __construct(\MysqliDb $mysql) |
| 29 | + { |
| 30 | + $this->model = 'MyClass'; |
| 31 | + $this->table = 'my_class'; |
| 32 | + $this->primaryKey = 'id'; |
| 33 | + $this->foreignKey = 'my_class_id'; |
| 34 | + $this->fields = ['id', 'name']; |
| 35 | + $this->requiredFields = ['name']; |
| 36 | + $this->uniqueFields = ['name']; |
| 37 | + $this->hasMany = ['MyClassProperties']; |
| 38 | + $this->hasAndBelongsToMany = ['Users']; |
| 39 | + |
| 40 | + parent::__construct($mysql); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +``` |
| 45 | + |
| 46 | +### Constructor Properties |
| 47 | +* model: string |
| 48 | +* table: string |
| 49 | +* primaryKey: string |
| 50 | +* foreignKey: string |
| 51 | +* fields: array |
| 52 | +* requiredFields: array |
| 53 | +* uniqueFields: array |
| 54 | +* hasMany: array |
| 55 | +* belongsTo: array |
| 56 | +* hasAndBelongsToMany: array |
| 57 | + |
| 58 | +### Methods |
| 59 | +* getAll() : array |
| 60 | +* getById(int $modelId) : array |
| 61 | +* getBySearch(array ['key' => 'value']) : array |
| 62 | +* insert(array $data) : array |
| 63 | +* updateById(int $modelId, array $data) : array |
| 64 | +* deleteById(int $modelId): void |
0 commit comments