![]() |
NanoFramework 1.4.0
A tiny PHP Framework
|
Connects to the database. More...
Public Member Functions | |
| __construct () | |
| findAll () | |
| find (int $id) | |
| insert (array $data) | |
| update (int $id, array $data) | |
| delete (int $id) | |
| where (string $key, mixed $value) | |
| getLastInsertedId () | |
| validate (array $data, string $ruleset, array &$errors=[]) | |
| findAll () | |
| find (int $id) | |
| insert (array $data) | |
| update (int $id, array $data) | |
| delete (int $id) | |
| where (string $key, mixed $value) | |
| getLastInsertedId () | |
| validate (array $data, string $ruleset, array &$errors=[]) | |
Static Public Member Functions | |
| static | now () |
Protected Member Functions | |
| min_length (string $field, array $data, string $params, &$error) | |
| max_length (string $field, array $data, string $params, &$error) | |
| valid_email (string $field, array $data, string $params, &$error) | |
| match (string $field, array $data, string $params, &$error) | |
| required (string $field, array $data, string $params, &$error) | |
Protected Attributes | |
| $table | |
| $validation | |
| $useTimestamps = true | |
Connects to the database.
By "database", understand "FakeDb", a extremely poor way to store data in JSON files. This is one of the main reasons why NanoFramework should never be used in production.
| __construct | ( | ) |
| delete | ( | int | $id | ) |
Deletes data from the table.
| int | $id | the id of the data to delete |
Implements ModelInterface.
| find | ( | int | $id | ) |
Retrives the data with the given id or null if it doesn't exist.
| int | $id | the id of the data to retrive |
null Implements ModelInterface.
| findAll | ( | ) |
| getLastInsertedId | ( | ) |
Gives the last id inserted in the table.
Implements ModelInterface.
| insert | ( | array | $data | ) |
|
protected |
Returns true if the field contains the same value as the one passed as params.
| string | $field | The name of the field to check |
| array | $data | The whole data |
| string | $params | The name of the field to compare |
| &$error | A variable where to store the error message |
|
protected |
Returns true if the field isn't smaller than the param.
| string | $field | The name of the field to check |
| array | $data | The whole data |
| string | $params | The maximum expected length of the field content |
| &$error | A variable where to store the error message |
|
protected |
Returns true if the field isn't bigger than the param.
| string | $field | The name of the field to check |
| array | $data | The whole data |
| string | $params | The minimum expected length of the field content |
| &$error | A variable where to store the error message |
|
static |
|
protected |
| update | ( | int | $id, |
| array | $data | ||
| ) |
Updates the table with new data.
| int | $id | the id of the element to update |
| array | $data | the new version of the data |
Implements ModelInterface.
|
protected |
Returns true if the field contains a valid email address.
| string | $field | The name of the field to check |
| array | $data | The whole data |
| string | $params | Unused |
| &$error | A variable where to store the error message |
| validate | ( | array | $data, |
| string | $ruleset, | ||
| array & | $errors = [] |
||
| ) |
Validates the given data against a ruleset.
In order to use the model validator, one must first redefine the $validation attribute in the class. That attribute is an associative array having a ruleset name as a key and an associative array describing the rules as a value.
Example of a valid validation rulesets:
| array | $data | The data to validate as an associative array |
| string | $ruleset | The name of the ruleset to use |
| array | &$errors | An array where to store the error data if any |
Implements ModelInterface.
| where | ( | string | $key, |
| mixed | $value | ||
| ) |
Adds a criteria about the request.
| string | $key | The key to filter |
| mixed | $value | The value to keep |
Implements ModelInterface.
|
protected |