PHP Класс ManaPHP\Mvc\Model

Наследование: extends ManaPHP\Component, implements ManaPHP\Mvc\ModelInterface
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$_initialized array
$_snapshot array

Открытые методы

Метод Описание
__callStatic ( string $method, integer | string $arguments ) : array | false | integer | Model | static[]
__construct ( array $data = [], ManaPHP\DiInterface $dependencyInjector = null ) \ManaPHP\Mvc\Model constructor
assign ( array $data, array $whiteList = null ) : static Assigns values to a model from an array
average ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : double Allows to calculate the average value on a column matching the specified conditions
count ( string | array $parameters = null, string $column = '*', integer | array $cacheOptions = null ) : integer | array Allows to count how many records match the specified conditions
create ( array $data = null, array $whiteList = null ) : void Inserts a model instance. If the instance already exists in the persistence it will throw an exception Returning true on success or false otherwise.
delete ( ) : void Deletes a model instance. Returning true on success or false otherwise.
deleteAll ( string | array $conditions, array $bind = [] ) : integer
exists ( string | array $parameters = null, integer | array $cacheOptions = null ) : boolean
find ( string | array $parameters = null, integer | array $cacheOptions = null ) : static[] Allows to query a set of records that match the specified conditions
findAll ( string | array $parameters = null, integer | array $cacheOptions = null ) : static[] alias of find
findFirst ( string | array $parameters = null, integer | array $cacheOptions = null ) : static | false Allows to query the first record that match the specified conditions
getChangedFields ( ) : array Returns a list of changed values
getReadConnection ( ) : ManaPHP\DbInterface Gets the connection used to read data for the model
getReadConnectionService ( ) : string Returns the DependencyInjection connection service name used to read data related the model
getSnapshotData ( ) : array Returns the internal snapshot data
getSource ( ) : string Returns table name mapped in the model
getWriteConnection ( ) : ManaPHP\DbInterface Gets the connection used to write data to the model
getWriteConnectionService ( ) : string Returns the DependencyInjection connection service name used to write data related to the model
hasChanged ( string | array $fields ) : boolean Check if a specific attribute has changed This only works if the model is keeping data snapshots
max ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed Allows to get the max value of a column that match the specified conditions
min ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed Allows to get the min value of a column that match the specified conditions
query ( ManaPHP\DiInterface $dependencyInjector = null ) : ManaPHP\Mvc\Model\QueryBuilderInterface Create a criteria for a specific model
save ( array $data = null, array $whiteList = null ) : void Inserts or updates a model instance. Returning true on success or false otherwise.
setConnectionService ( string $connectionService ) : static Sets the DependencyInjection connection service name
setReadConnectionService ( string $connectionService ) : static Sets the DependencyInjection connection service name used to read data
setSource ( string $source ) : static Sets table name which model should be mapped
setWriteConnectionService ( string $connectionService ) : static Sets the DependencyInjection connection service name used to write data
sum ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed Allows to calculate a summary on a column that match the specified conditions
toArray ( ) : array Returns the instance as an array representation
update ( array $data = null, array $whiteList = null ) : void Updates a model instance. If the instance does n't exist in the persistence it will throw an exception Returning true on success or false otherwise.
updateAll ( array $columnValues, string | array $conditions, array $bind = [] ) : integer

Защищенные методы

Метод Описание
_doLowInsert ( ) : void Sends a pre-build INSERT SQL statement to the relational database system
_doLowUpdate ( ) : void Sends a pre-build UPDATE SQL statement to the relational database system
_exists ( ) : boolean Checks if the current record already exists or not
_fireEvent ( string $eventName ) : void Fires an event, implicitly calls behaviors and listeners in the events manager are notified
_fireEventCancel ( string $eventName ) : boolean Fires an internal event that cancels the operation
_groupResult ( string $function, string $alias, string $column, string | array $parameters, integer | array $cacheOptions ) : mixed Generate a SQL SELECT statement for an aggregate

Описание методов

__callStatic() публичный статический Метод

public static __callStatic ( string $method, integer | string $arguments ) : array | false | integer | Model | static[]
$method string
$arguments integer | string
Результат array | false | integer | Model | static[]

__construct() закрытый публичный Метод

\ManaPHP\Mvc\Model constructor
final public __construct ( array $data = [], ManaPHP\DiInterface $dependencyInjector = null )
$data array
$dependencyInjector ManaPHP\DiInterface

_doLowInsert() защищенный Метод

Sends a pre-build INSERT SQL statement to the relational database system
protected _doLowInsert ( ) : void
Результат void

_doLowUpdate() защищенный Метод

Sends a pre-build UPDATE SQL statement to the relational database system
protected _doLowUpdate ( ) : void
Результат void

_exists() защищенный Метод

Checks if the current record already exists or not
protected _exists ( ) : boolean
Результат boolean

_fireEvent() защищенный Метод

Fires an event, implicitly calls behaviors and listeners in the events manager are notified
protected _fireEvent ( string $eventName ) : void
$eventName string
Результат void

_fireEventCancel() защищенный Метод

Fires an internal event that cancels the operation
protected _fireEventCancel ( string $eventName ) : boolean
$eventName string
Результат boolean

_groupResult() защищенный статический Метод

Generate a SQL SELECT statement for an aggregate
protected static _groupResult ( string $function, string $alias, string $column, string | array $parameters, integer | array $cacheOptions ) : mixed
$function string
$alias string
$column string
$parameters string | array
$cacheOptions integer | array
Результат mixed

assign() публичный Метод

$robot->assign(array( 'type' => 'mechanical', 'name' => 'Boy', 'year' => 1952 ));
public assign ( array $data, array $whiteList = null ) : static
$data array
$whiteList array
Результат static

average() публичный статический Метод

What's the average price of robots? $average = Robots::average(array('column' => 'price')); echo "The average price is ", $average, "\n"; What's the average price of mechanical robots? $average = Robots::average(array("type='mechanical'", 'column' => 'price')); echo "The average price of mechanical robots is ", $average, "\n";
public static average ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : double
$column string
$parameters string | array
$cacheOptions integer | array
Результат double

count() публичный статический Метод

How many robots are there? $number = Robots::count(); echo "There are ", $number, "\n"; How many mechanical robots are there? $number = Robots::count("type='mechanical'"); echo "There are ", $number, " mechanical robots\n";
public static count ( string | array $parameters = null, string $column = '*', integer | array $cacheOptions = null ) : integer | array
$parameters string | array
$column string
$cacheOptions integer | array
Результат integer | array

create() публичный Метод

Creating a new robot $robot = new Robots(); $robot->type = 'mechanical'; $robot->name = 'Boy'; $robot->year = 1952; $robot->create(); Passing an array to create $robot = new Robots(); $robot->create(array( 'type' => 'mechanical', 'name' => 'Boy', 'year' => 1952 ));
public create ( array $data = null, array $whiteList = null ) : void
$data array
$whiteList array
Результат void

delete() публичный Метод

$robot = Robots::findFirst("id=100"); $robot->delete(); foreach (Robots::find("type = 'mechanical'") as $robot) { $robot->delete(); }
public delete ( ) : void
Результат void

deleteAll() публичный статический Метод

public static deleteAll ( string | array $conditions, array $bind = [] ) : integer
$conditions string | array
$bind array
Результат integer

exists() публичный статический Метод

public static exists ( string | array $parameters = null, integer | array $cacheOptions = null ) : boolean
$parameters string | array
$cacheOptions integer | array
Результат boolean

find() публичный статический Метод

How many robots are there? $robots = Robots::find(); echo "There are ", count($robots), "\n"; How many mechanical robots are there? $robots = Robots::find("type='mechanical'"); echo "There are ", count($robots), "\n"; Get and print virtual robots ordered by name $robots = Robots::find(array("type='virtual'", "order" => "name")); foreach ($robots as $robot) { echo $robot->name, "\n"; } Get first 100 virtual robots ordered by name $robots = Robots::find(array("type='virtual'", "order" => "name", "limit" => 100)); foreach ($robots as $robot) { echo $robot->name, "\n"; }
public static find ( string | array $parameters = null, integer | array $cacheOptions = null ) : static[]
$parameters string | array
$cacheOptions integer | array
Результат static[]

findAll() закрытый публичный статический Метод

alias of find
final public static findAll ( string | array $parameters = null, integer | array $cacheOptions = null ) : static[]
$parameters string | array
$cacheOptions integer | array
Результат static[]

findFirst() публичный статический Метод

What's the first robot in robots table? $robot = Robots::findFirst(); echo "The robot name is ", $robot->name; What's the first mechanical robot in robots table? $robot = Robots::findFirst("type='mechanical'"); echo "The first mechanical robot name is ", $robot->name; Get first virtual robot ordered by name $robot = Robots::findFirst(array("type='virtual'", "order" => "name")); echo "The first virtual robot name is ", $robot->name;
public static findFirst ( string | array $parameters = null, integer | array $cacheOptions = null ) : static | false
$parameters string | array
$cacheOptions integer | array
Результат static | false

getChangedFields() публичный Метод

Returns a list of changed values
public getChangedFields ( ) : array
Результат array

getReadConnection() публичный Метод

Gets the connection used to read data for the model
public getReadConnection ( ) : ManaPHP\DbInterface
Результат ManaPHP\DbInterface

getReadConnectionService() публичный Метод

Returns the DependencyInjection connection service name used to read data related the model
public getReadConnectionService ( ) : string
Результат string

getSnapshotData() публичный Метод

Returns the internal snapshot data
public getSnapshotData ( ) : array
Результат array

getSource() публичный Метод

Returns table name mapped in the model
public getSource ( ) : string
Результат string

getWriteConnection() публичный Метод

Gets the connection used to write data to the model
public getWriteConnection ( ) : ManaPHP\DbInterface
Результат ManaPHP\DbInterface

getWriteConnectionService() публичный Метод

Returns the DependencyInjection connection service name used to write data related to the model
public getWriteConnectionService ( ) : string
Результат string

hasChanged() публичный Метод

Check if a specific attribute has changed This only works if the model is keeping data snapshots
public hasChanged ( string | array $fields ) : boolean
$fields string | array
Результат boolean

max() публичный статический Метод

What is the max robot id? $id = Robots::max(array('column' => 'id')); echo "The max robot id is: ", $id, "\n"; What is the max id of mechanical robots? $sum = Robots::max(array("type='mechanical'", 'column' => 'id')); echo "The max robot id of mechanical robots is ", $id, "\n";
public static max ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed
$column string
$parameters string | array
$cacheOptions integer | array
Результат mixed

min() публичный статический Метод

What is the min robot id? $id = Robots::min(array('column' => 'id')); echo "The min robot id is: ", $id; What is the min id of mechanical robots? $sum = Robots::min(array("type='mechanical'", 'column' => 'id')); echo "The min robot id of mechanical robots is ", $id;
public static min ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed
$column string
$parameters string | array
$cacheOptions integer | array
Результат mixed

query() публичный статический Метод

Create a criteria for a specific model
public static query ( ManaPHP\DiInterface $dependencyInjector = null ) : ManaPHP\Mvc\Model\QueryBuilderInterface
$dependencyInjector ManaPHP\DiInterface
Результат ManaPHP\Mvc\Model\QueryBuilderInterface

save() публичный Метод

Creating a new robot $robot = new Robots(); $robot->type = 'mechanical'; $robot->name = 'Boy'; $robot->year = 1952; $robot->save(); Updating a robot name $robot = Robots::findFirst("id=100"); $robot->name = "Biomass"; $robot->save();
public save ( array $data = null, array $whiteList = null ) : void
$data array
$whiteList array
Результат void

setConnectionService() публичный Метод

Sets the DependencyInjection connection service name
public setConnectionService ( string $connectionService ) : static
$connectionService string
Результат static

setReadConnectionService() публичный Метод

Sets the DependencyInjection connection service name used to read data
public setReadConnectionService ( string $connectionService ) : static
$connectionService string
Результат static

setSource() публичный Метод

Sets table name which model should be mapped
public setSource ( string $source ) : static
$source string
Результат static

setWriteConnectionService() публичный Метод

Sets the DependencyInjection connection service name used to write data
public setWriteConnectionService ( string $connectionService ) : static
$connectionService string
Результат static

sum() публичный статический Метод

How much are all robots? $sum = Robots::sum(array('column' => 'price')); echo "The total price of robots is ", $sum, "\n"; How much are mechanical robots? $sum = Robots::sum(array("type='mechanical'", 'column' => 'price')); echo "The total price of mechanical robots is ", $sum, "\n";
public static sum ( string $column, string | array $parameters = null, integer | array $cacheOptions = null ) : mixed
$column string
$parameters string | array
$cacheOptions integer | array
Результат mixed

toArray() публичный Метод

print_r($robot->toArray());
public toArray ( ) : array
Результат array

update() публичный Метод

Updating a robot name $robot = Robots::findFirst("id=100"); $robot->name = "Biomass"; $robot->update();
public update ( array $data = null, array $whiteList = null ) : void
$data array
$whiteList array
Результат void

updateAll() публичный статический Метод

public static updateAll ( array $columnValues, string | array $conditions, array $bind = [] ) : integer
$columnValues array
$conditions string | array
$bind array
Результат integer

Описание свойств

$_initialized защищенное статическое свойство

protected static array $_initialized
Результат array

$_snapshot защищенное свойство

protected array $_snapshot
Результат array