NanoFramework 1.5.2
A tiny PHP Framework
Loading...
Searching...
No Matches
ModelInterface Interface Reference

Interface that the user can implement in order to create a new Model, based on a real ODBC. More...

Inheritance diagram for ModelInterface:
Model

Public Member Functions

 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=[])
 

Detailed Description

Interface that the user can implement in order to create a new Model, based on a real ODBC.

This interface contains all the required functionalities needed for a new Model.

Definition at line 10 of file ModelInterface.php.

Member Function Documentation

◆ delete()

delete ( int $id)

Deletes data from the table.

Parameters
int$idthe id of the data to delete

Implemented in Model.

◆ find()

find ( int $id)

Retrives the data with the given id or null if it doesn't exist.

Parameters
int$idthe id of the data to retrive
Returns
null|array The data found or null

Implemented in Model.

◆ findAll()

findAll ( )

Retrieves all the data in the table.

Returns
array All the data

Implemented in Model.

◆ getLastInsertedId()

getLastInsertedId ( )

Gives the last id inserted in the table.

Returns
int The last id inserted or 0 if the table is empty

Implemented in Model.

◆ insert()

insert ( array $data)

Inserts the data in the table.

Parameters
array$datathe data to insert

Implemented in Model.

◆ update()

update ( int $id,
array $data )

Updates the table with new data.

Parameters
int$idthe id of the element to update
array$datathe new version of the data

Implemented in Model.

◆ validate()

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:

protected $validation = [
'user' => [
'username' => 'required|max_length:255',
'email' => 'required|valid_email',
'password' => 'required|min_length:8',
'password_retype' => 'match:password'
],
'login' => [
'username' => 'required',
'password' => 'required'
]
];
Parameters
array$dataThe data to validate as an associative array
string$rulesetThe name of the ruleset to use
array&$errorsAn array where to store the error data if any
Returns
bool If the given data is valid against the given ruleset

Implemented in Model.

◆ where()

where ( string $key,
mixed $value )

Adds a criteria about the request.

Parameters
string$keyThe key to filter
mixed$valueThe value to keep
Returns
ModelInterface $this for chaining

Implemented in Model.


The documentation for this interface was generated from the following file: