Methods

Implements dynamic Model_Crud::find_by_{column} and Model_Crud::find_one_by_{column} methods.

__callStatic(string $name, string $args) : mixed

Parameters

$name

string

The method name

$args

string

The method args

Exceptions

\BadMethodCallException

Returns

mixedBased on static::$return_type

Sets up the object.

__construct(array $data) 

Parameters

$data

array

The data array

Magic getter to fetch data from the data container

__get(string $property) : mixed

Parameters

$property

string

The property name

Returns

mixed

Magic isset to check if values exist

__isset(string $property) : bool

Parameters

$property

string

The property name

Returns

boolwhether or not the property exists

Magic setter so new objects can be assigned values

__set(string $property, mixed $value) : void

Parameters

$property

string

The property name

$value

mixed

The property value

Magic unset to remove existing properties

__unset(string $property) 

Parameters

$property

string

The property name

Count all of the rows in the table.

count(string $column, bool $distinct, array $where, string $group_by) : int

Parameters

$column

string

Column to count by

$distinct

bool

Whether to count only distinct rows (by column)

$where

array

Query where clause(s)

$group_by

string

Column to group by

Exceptions

\FuelException

Returns

intThe number of rows OR false

current()

current() 

Deletes this record and freezes the object

delete() : mixed

Returns

mixedRows affected

Finds all records.

find(array $config, string $key) : array | null

Parameters

$config

array

array containing query settings

$key

string

optional array index key

Returns

arraynullan array containing models or null if none are found

Finds all records in the table.

find_all(int $limit, int $offset) : null | object

Optionally limited and offset.

Parameters

$limit

int

Number of records to return

$offset

int

What record to start at

Returns

nullobjectNull if not found or an array of Model object

Finds all records where the given column matches the given value using the given operator ('=' by default).

find_by(string $column, mixed $value, string $operator, int $limit, int $offset) : null | object

Optionally limited and offset.

Parameters

$column

string

The column to search

$value

mixed

The value to find

$operator

string

The operator to search with

$limit

int

Number of records to return

$offset

int

What record to start at

Returns

nullobjectNull if not found or an array of Model object

Finds a row with the given primary key value.

find_by_pk(mixed $value) : null | object

Parameters

$value

mixed

The primary key value to find

Returns

nullobjectEither null or a new Model object

Finds a row with the given column value.

find_one_by(mixed $column, mixed $value, string $operator) : null | object

Parameters

$column

mixed

The column to search

$value

mixed

The value to find

$operator

string

Returns

nullobjectEither null or a new Model object

Forges new Model_Crud objects.

forge(array $data) : \Fuel\Core\Model_Crud

Parameters

$data

array

Model data

Returns

Either checks if the record is frozen or sets whether it is frozen or not.

frozen(bool | null $frozen) : bool | \Fuel\Core\Model_Crud

fluent This method is part of a fluent interface and will return the same instance

Parameters

$frozen

boolnull

Whether this is a frozen record

Returns

Either checks if the record is new or sets whether it is new or not.

is_new(bool | null $new) : bool | \Fuel\Core\Model_Crud

fluent This method is part of a fluent interface and will return the same instance

Parameters

$new

boolnull

Whether this is a new record

Returns

key()

key() 

Checks if the given offset (class property) exists.

offsetExists(string $offset) : bool

Parameters

$offset

string

class property

Returns

bool

Gets the value of the given offset (class property).

offsetGet(string $offset) : mixed

Parameters

$offset

string

class property

Returns

mixed

Sets the value of the given offset (class property).

offsetSet(string $offset, string $value) : void

Parameters

$offset

string

class property

$value

string

value

Unsets the given offset (class property).

offsetUnset(string $offset) : void

Parameters

$offset

string

class property

Implementation of the Iterator interface

rewind() 

Enable sanitization mode in the object

sanitize() : \Fuel\Core\Model_Crud

fluent This method is part of a fluent interface and will return the same instance

Returns

Returns the current sanitization state of the object

sanitized() : bool

Returns

bool

Saves the object to the database by either creating a new record or updating an existing record.

save(bool $validate) : array | int

Sets the default values if set.

Parameters

$validate

bool

whether to validate the input

Exceptions

\Exception

Returns

arrayintRows affected and or insert ID

Serializable implementation: serialize

serialize() : array

Returns

arraymodel data

Sets an array of values to class properties

set(array $data) : \Fuel\Core\Model_Crud

fluent This method is part of a fluent interface and will return the same instance

Parameters

$data

array

The data

Returns

Returns all of $this object's public properties as an associative array.

to_array() : array

Returns

array

Disable sanitization mode in the object

unsanitize() : \Fuel\Core\Model_Crud

fluent This method is part of a fluent interface and will return the same instance

Returns

Serializable implementation: unserialize

unserialize(string $data) : array

Parameters

$data

string

Returns

arraymodel data

valid()

valid() 

Returns whether the instance will pass validation.

validates() : bool

Returns

boolwhether the instance passed validation

Returns the a validation object for the model.

validation() : object

Returns

objectValidation object

Get the connection to use for reading or writing

get_connection(boolean $writable) : mixed

Parameters

$writable

boolean

Get a writable connection

Returns

mixedDatabase profile name (string) or Database_Connection (object)

Gets called after the delete query is executed and right before it is returned.

post_delete(int $result) : int

Parameters

$result

int

Number of affected rows

Returns

int

Gets called after the query is executed and right before it is returned.

post_find(array | null $result) : array | null

$result will be null if 0 rows are returned.

Parameters

$result

arraynull

the result array or null when there was no result

Returns

arraynull

Gets called after the insert query is executed and right before it is returned.

post_save(array $result) : array

Parameters

$result

array

insert id and number of affected rows

Returns

array

Gets called after the update query is executed and right before it is returned.

post_update(int $result) : int

Parameters

$result

int

Number of affected rows

Returns

int

Called right after the validation is ran.

post_validate(bool $result) : bool

Parameters

$result

bool

Validation result

Returns

bool

Gets called before the delete query is executed.

pre_delete(\Fuel\Core\Database_Query $query) : void

Must return the query object.

Parameters

$query

\Fuel\Core\Database_Query

The query object

Gets called before the query is executed.

pre_find(\Fuel\Core\Database_Query $query) : void

Must return the query object.

Parameters

$query

\Fuel\Core\Database_Query

The query object

Gets called before the insert query is executed.

pre_save(\Fuel\Core\Database_Query $query) : void

Must return the query object.

Parameters

$query

\Fuel\Core\Database_Query

The query object

Gets called before the update query is executed.

pre_update(\Fuel\Core\Database_Query $query) : void

Must return the query object.

Parameters

$query

\Fuel\Core\Database_Query

The query object

Gets called before the validation is ran.

pre_validate(array $data) : array

Parameters

$data

array

The validation data

Returns

array

Called right after values retrieval, before save, update, setting defaults and validation.

prep_values(array $values) : array

Parameters

$values

array

input array

Returns

array

Get the primary key for the current Model

primary_key() : string

Returns

string

Run validation

run_validation(array $vars) : bool

Parameters

$vars

array

array to validate

Returns

boolvalidation result

 Properties

 

<p>Data container for this object</p>

$_data : array

 

<p>If this is a record is frozen</p>

$_is_frozen : bool

 

<p>If this is a new record</p>

$_is_new : bool

 

<p>If this is a records data will be sanitized on get</p>

$_sanitization_enabled : bool

 

<p>The validation instance</p>

$_validation : object