Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications


API >> mvc >> models
Models contain your data access methods. The model file must contain a class inside it with the same name as the filename plus "Model" appended to it, eg. in a crayons file you would have a crayonsModel class. You can name the methods within anything that you like. Only public methods will be accessible from your controllers and components.
Each method within a model has access to your database connection via $this->db (for the primary connection, additional connections are as you named them in the .config eg.: $this->dbro or $this->dbmaster). Through this object you can access all the database methods built-in to the PHP extension of your database, eg.: $this->db->query() as well as the Vork database convenience features, eg.:
$str $this->db->cleanString($str);

Vork database convenience functions:

$this->db->pquery($sql [, $arg1 [, $arg2...]] )

Direct replacement for query() that adds automatic value cleansing and substitution.
Uses a question-mark (prepared-statement style) as placeholder for variables, eg.:
$quantity 7;
$name $_POST['name'];
$id 613;
$color 'blue';
$sql 'update widgets set quantity=?, name=? where id=? and color=?';

Alternatively you can send the parameters in an array:
$params = array($quantity$name$id$color);

Or even mix the two formats:
$params = array($name$id);


Removes any potentially-harmful characters (Google for: SQL injection) and wraps the string in quotes, ready for use within your SQL statement.
cleanString() can accept either a single string or an array of strings and will return the cleaned string/array-of-strings in the same format that was sent to it (array-keys will be preserved.)


Generates ANSI-standard insert syntax to insert data into the database for one or more rows (using a single-query). The array keys of the $args argument are:
table - required
vals - required, can be a string (for inserting into one column only), an array of column values or an array containing multiple subarrays of column values to insert multiple rows with one query. The array keys in the vals argument can be set to correspond to the column names as an alternative to setting the cols argument (below.) If both are set, cols takes precedence.
cols - optional, it is highly recommended to always include this to ensure that nothing breaks if you modify the table structure


Same as insertSql() but also will update the data if it exists already.
This method uses MySQL/SQLite-specific SQL syntax and is not available with other databases.

$this->db->getColumnTypeSql($table, $column)

MySQL-Specific function to get the table-column definition from the information_schema. This is used by the getEnumOptions() method.

$this->db->getEnumOptions($table, $column, $columnType = 'enum')

MySQL-Specific function to get all the options defined for a column of enum or set type.

$this->db->getDateFormat() or $this->db->DATE_FORMAT (constant in PHP 5.3+)

Convenient way to return a date column in the display format as defined in your .config, this is to ensure your application displays dates in a consistent manner.

$this->db->getDateTimeFormat() or $this->db->DATETIME_FORMAT (constant in PHP 5.3+)

Convenient way to return a date + time column in the display format as defined in your .config, this is to ensure your application displays dates/times in a consistent manner.