Source API for the «PorteTable» class

Methods used the manage a database table associated to a given model.

PHP magic methods

__construct

Construct a new table instance for provided type of record.

return
$porte
Porte
$type
string
__get

Overwrite PHP magick method "__get" method. Used to lazy create an even instance.

return
mixed
Vary according to the property
$property
string, Property
to retrieve
__call

Overwrite PHP magick method "__get" method. Used by plugins to attach method to a table instance.

return
$method
object
$args
object

Public methods

create

Create a new table, does not check if table exists.

return
boolean
True on success
exists

Check if table exists.

return
boolean
True if table exists, false otherwise
drop

Delete a table if it exists.

return
Current
table instance
update

Create the table schema for the record. Handle all sort of relationship, if an existing table exists, new fields will be created but does not yet handle the migration of existing fields.
Note, field present in the database table and not referenced in the object will removed (it is planned to have this configurable).

Options may include:

  • clean: Delete undefined field in model
return
boolean
True on success
clear

Remove all the records present in the database table and reset the increment value to 0.

return
PorteTable
Current object
fields

List all the fields defined in the database table.

To get an array of all the fields:
$fields = array_keys( $user->fields() );

return
array
Fields with field names as keys
indexes

List all the indexes defined in the database table.

return
array
Indexes with index names as keys
load

Load a record

return
mixed
New PorteRecord if no argument, loaded PorteRecord if match, false if more than one record returned
records

This method is not yet documented.

find

The find method return an array of entities. You could use this function in the following ways:
$user->find('username=? AND password=?',array('my username','my password')) $user->find(array('order_by'=>'date_of_creation','direction'=>'asc')) $user->find('group_id=?',array(4),array('order_by'=>'date_of_creation','direction'=>'asc')) The properties available in the options array are:

  • sql (string, may contains ?)
  • params (array, match sql ?)
  • tables (array or string list)
  • select (select query)
  • where (where query)
  • order_by (field name)
  • group_by (field name)
  • having (string)
  • direction (asc or desc, >0 or = 0, true or false)
  • limit (int or string)
  • offset (int or string)
  • return_sql (boolean) Return the SQL query used to select the records
  • return_builder (boolean) Return an array containing the keys "select", "from", "where", "group_by", "having", "order_by" ,"direction" and "limit"
  • return_array (boolean) Return an array of arrays instead of a PorteIterator object of PorteRecord objects
count

Count the number of records in the table.

Counted records may be altered with optional arguments. Argument may be provided in a similar form than in the "find" method.

Available options:

  • where: SQL where clause

Exempe $table->count() $table->count('age=?',array(18));

delete

Delete records present in a table.

Deleted records may be filtered with optional arguments. Argument may be provided in a similar form than in the "find" method.

Available options:

	where: SQL where clause

Exemple:

	$table->delete()
	$table->delete('age=?',array(18));
distinct

Retrieve the distinct values for a provided property.

return
array
List of values
$property
string