Nos\Orm\Model¶Extends Model of FuelPHP ORM.
Novius OS Model have some differences compare with FuelPHP Model :
- Novius OS implements a cache mechanism for properties when they are fetched from the database. By default, cache files are save in
NOSPATH/local/cache/fuelphp/list_columns.- In property definition, put
convert_empty_to_nullkey totrueif you want that this property stores a null value when it receives empty string.
Nos\Orm\Model::$title_property¶$iitem as parameter).title, label or name in its name, or (as last resort) the first varchar.Nos\Orm\Model::$attachment¶Defines the attachments of a model. Attachment is a special type of relations created for Novius OS. See Nos\Attachment.
Nos\Orm\Model::$providers¶Defines the behaviours of model.
| Relation: | Required. Wherein the relation is based on the provider. Must be a multiple relation and have cascade_save activate. |
|---|---|
| Value_property: | Optional. Set to value if empty. The fields containing the provider value. |
| Key_property: | Optional. Set to key if empty. The fields containing the provider key. |
| Value_relation: | Optional. If set, must contains a single relation name and then the provider value become the model. |
In Novius OS, you can configure model by a file configuration.
For sample: if in your application you define a Model_Monkey class, you can create a file config/model/monkey.config.php to extend configuration.
All this attributes can be defined in configuration file : properties, table_name, title_property, observers,
behaviours, providers and all relations types (has_many, belongs_to,
has_one, many_many, twinnable_has_many, twinnable_belongs_to, twinnable_has_one, twinnable_many_many
and attachment).
Example in the class definition:
<?php
class Model_Example extends \Nos\Orm\Model
{
// In this example, attachments use defaults properties
protected static $_attachment = array(
'avatar' => array(),
'cv' => array(),
);
protected static $_behaviours = array(
'Nos\Orm_Behaviour_Contextable' => array(
'events' => array('before_insert'),
'context_property' => 'ex_context',
),
);
// In this example, use a column name for defined title_property
protected static $_title_property = 'ex_reference';
Example in configuration file:
<?php
return array(
'attachment' => array(
'avatar' => array(
'dir' => 'namespace/model_name/avatar/',
'image' => true,
'alias' => 'avatar',
),
'curriculum_vitae' => array(
'dir' => 'namespace/model_name/curriculum_vitae/',
'alias' => 'cv',
'extensions' => array('doc', 'odt', 'pdf'),
'check' => array('ClassName', 'methodName'),
),
),
'behaviours' => array(
'Nos\Orm_Behaviour_Contextable' => array(
'events' => array('before_insert'),
'context_property' => 'ex_context',
),
),
// In this example, use a closure for defined title_property
'title_property' => function($item) {
return $item->ex_reference;
},
);
Nos\Orm\Model::$linked_wysiwygs¶Nos\Model_WysiwygNos\Orm\Model::$linked_medias¶Nos\Media\Model_LinkWarning
Don’t use these relations directly, we created providers for them.
Nos\Orm\Model::$medias¶Provider for Nos\Media\Model_Link linked to model.
<?php
$item->medias->avatar; // Get a Model_Link named 'avatar'
$item->medias->avatar->media; // Get Model_Media named 'avatar'
$item->medias->cv = $Model_Media; // Attach a Model_Media named 'cv'
$item->medias->cv = null; // Detach a media from an item
// or
unset($item->medias->cv);
Nos\Orm\Model::$wysiwygs¶Provider for Nos\Model_Wysiwyg linked to model.
<?php
$item->wysiwygs->content; // Get a Model_Wysiwyg named 'content'
$item->wysiwygs->content->wysiwyg_text; // Get content of Model_Wysiwyg named 'content'
$item->wysiwygs->summary = 'foo'; // Set a Model_Wysiwyg named 'content', with content 'foo'.
$item->wysiwygs->summary = null; // Remove a wysiwyg from an item
// or
unset($item->wysiwygs->summary);
Nos\Orm\Model::title_property¶| Returns: | Title property of model. See Model::$title_property. |
|---|
Nos\Orm\Model::table¶| Returns: | The DB table name of model. |
|---|
Nos\Orm\Model::behaviours($specific = null, $default = null)¶Nos\Orm\Model::add_properties($properties)¶| Parameters: |
|
|---|
Nos\Orm\Model::addRelation($type, $name, array $options = array())¶Add a relation to model
| Parameters: |
|
|---|---|
| Throws: |
|
Nos\Orm\Model::providers($specific = null, $default = null)¶Get the class’s providers and what they provide
| Parameters: |
|
|---|---|
| Throws: |
|
| Returns: | The specific provider if it exist and is requested or the defaut value. Else, array of all providers. |
Nos\Orm\Model::addProvider($name, array $properties)¶Add a provider to model
| Parameters: |
|
|---|---|
| Throws: |
|
Nos\Orm\Model::configModel¶| Returns: | Array configurations of the model. |
|---|
Nos\Orm\Model::getApplication¶| Returns: | Application name of the model. |
|---|
Nos\Orm\Model::event($method, $args = array())¶Trigger an event (caught by behaviours) on the item.
| Parameters: |
|
|---|
Nos\Orm\Model::eventStatic($method, $args = array())¶Trigger an event (caught by behaviours) on the model class.
| Parameters: |
|
|---|
Nos\Orm\Model::prefix¶| Returns: | Prefix of column name. Computed from the primary key name (everything before the first _ character). |
|---|
Nos\Orm\Model::title_item()¶| Returns: | Returns the item’s title, calculated from Model::$title_property. |
|---|
Nos\Orm\Model::pick($column[, $column[, $column[, ...]]])¶| Parameters: |
|
|---|---|
| Returns: | Returns the first non empty column. Will add column prefix (see |