\Piko\DbRecord
DbRecord represents a database table’s row and implements the Active Record pattern.
Constants summary
Name | Description |
---|---|
public TYPE_BOOL |
|
public TYPE_INT |
|
public TYPE_STRING |
Properties summary
Name | Description |
---|---|
protected $data |
|
protected $db |
The database instance. |
protected $primaryKey |
The name of the primary key. Default to 'id'. |
protected $schema |
A name-value pair that describes the structure of … |
protected $tableName |
The name of the table. |
Inherited Properties
Name | Description |
---|---|
protected $errors |
Errors hash container |
protected $eventDispatcher |
|
protected $listenerProvider |
Methods summary
Name | Description |
---|---|
public __construct |
Constructor |
public __get |
Magick method to access rows's data as class attri… |
public __isset |
Magick method to check if attribute is defined in … |
public __set |
Magick method to set row's data as class attribute… |
public __unset |
Magick method to unset attribute in row's data. |
public bind |
Override ModelTrait::bind() |
public delete |
Delete this record. |
public load |
Load row data. |
public save |
Save this record into the table. |
public toArray |
Override ModelTrait::toArray() |
protected afterDelete |
Method called after a delete action. |
protected afterSave |
Method called after a save action. |
protected beforeDelete |
Method called before a delete action. |
protected beforeSave |
Method called before a save action. |
protected checkColumn |
Check if column name is defined in the table schem… |
Inherited Methods
Name | Description |
---|---|
public bind |
Bind the data to the model attribubes. |
public getErrors |
Return the errors hash container |
public isValid |
Check if the model is valid |
public on |
|
public toArray |
Get the model data as an associative array. |
public trigger |
Trigger an event that may be listen by event liste… |
protected getAttributes |
Get the public properties reprenting the data mode… |
protected setError |
Set an error that will be appended to the errors c… |
protected validate |
Validate this model (Should be extended). Inherite… |
public $TYPE_BOOL
public $TYPE_INT
public $TYPE_STRING
Properties
protected $data : array<string,string|int|bool>
protected $db : \PDO
The database instance.
protected $primaryKey : string
The name of the primary key. Default to ‘id’.
protected $schema : int[]
A name-value pair that describes the structure of the table.
eg.['id' => self::TYPE_INT, 'name' => 'id' => self::TYPE_STRING]
protected $tableName : string
The name of the table.
Methods
public __construct(): mixed
public __construct(\PDO $db): mixed
Constructor
Parameters
$db : A PDO instance
Return:
mixed
public __get(): mixed
public __get(string $attribute): mixed
Magick method to access rows’s data as class attribute.
Parameters
$attribute : The attribute’s name.
Return:
mixed The attribute’s value.
public __isset(): mixed
public __isset(string $attribute): mixed
Magick method to check if attribute is defined in row’s data.
Parameters
$attribute : The attribute’s name.
Return:
mixed
public __set(): void
public __set(string $attribute, string|int|bool $value): void
Magick method to set row’s data as class attribute.
Parameters
$attribute : The attribute’s name.
$value : The attribute’s value.
public __unset(): mixed
public __unset(string $attribute): mixed
Magick method to unset attribute in row’s data.
Parameters
$attribute : The attribute’s name.
Return:
mixed
public bind(): void
public bind(array<string,string|int|bool> $data): void
Override ModelTrait::bind()
Parameters
$data :
public delete(): bool
public delete(): bool
Delete this record.
throws \RuntimeException
Return:
bool
public load(): static
public load(\Piko\number $id): static
Load row data.
Parameters
$id : The value of the row primary key.
throws \RuntimeException
Return:
static
public save(): bool
public save(): bool
Save this record into the table.
throws \RuntimeException
Return:
bool
public toArray(): array
public toArray(): array
Override ModelTrait::toArray()
Return:
array
protected afterDelete(): void
protected afterDelete(): void
Method called after a delete action.
protected afterSave(): void
protected afterSave(): void
Method called after a save action.
protected beforeDelete(): bool
protected beforeDelete(): bool
Method called before a delete action.
Return:
bool
protected beforeSave(): bool
protected beforeSave(bool $insert): bool
Method called before a save action.
Parameters
$insert : If the row is a new record, the value will be true, otherwise, false.
Return:
bool
protected checkColumn(): void
protected checkColumn(string $name): void
Check if column name is defined in the table schema.
Parameters
$name :
throws \RuntimeException
see \Piko\DbRecord::$schema