-
Notifications
You must be signed in to change notification settings - Fork 1
Models
At the heart of an MVC architecture are models. Models represent some reproducible entity, like a user, a task, or a bank account. Typically, models will be backed by persistent storage. Infuse Framework includes boilerplate code for managing models, such as, creating, editing, and deleting. All of the interactions with the database have been abstracted out, although you are free to override any of the model functions.
Example for a user model. This file would go in modules/users/models/User.php.
<?php
namespace infuse\models;
class User extends \infuse\Model
{
public static $properties = array(
'id' => array(
'type' => 'id'
),
'username' => array(
'type' => 'text'
'length' => 25
),
'password' => array(
'type' => 'password'
),
'address' => array(
'type' => 'longtext',
'length' => 200
)
);
}
In order to take advantage of the boilerplate model code, you must define the properties of the model. The name of the property cannot contain spaces. It is advised to use lowercase names with spaces delimited by an underscore (_).
The type of the property.
- id
- text
- longtext
- number
- boolean
- enum
- password
- date
- hidden
- custom
- html
Type: String
Required
The default value to be used when creating new models.
Type: String
Optional
The type of number when the property type is number.
Type: String
Default: int
Required if specifying number type
A key-value map of acceptable values for the enum type.
Type: Array
Required if specifying enum type
Type of the database column for the enum.
Type: String
Default: varchar
Required if specifying enum type
Overrides the default maximum length of the column values in the database. Use this when a different value is needed besides the one specified.
Type: Integer|String
Default: Chosen according to type
Optional
Specifies whether the column is allowed to have null values.
Type: Boolean
Default: false
Optional
An HTML string that will have values from the model injected. Only used in the admin panel.
Type: String
Example: <a href="/users/profile/{uid}">{username}</a>
Optional
Specifies whether the field is required when creating new models.
Type: Boolean
Default: false
Optional
Function reference to validate the input of the field (i.e. user creation, editing a user), returns true if valid. The function should look like function validate_email( &$property_value, $parameters ) The validation function is allowed to modify the property value.
Type: Array
Optional
An array of extra parameters to pass to the validation function. Comes through the second argument in an array.
Type: Array
Default: null
Optional
Prevents the column from being sortable in the admin panel.
Type: Boolean
Default: false
Optional
Prevents the column from wrapping in the admin panel.
Type: Boolean
Default: false
Optional
Prevents the column from truncating values in the admin panel.
Type: Boolean
Default: true
Optional
Title of the property that shows up in admin panel.
Type: String
Default: Derived from property name
Optional