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_null key to true if you want that this property stores a null value when it receives empty string.
Defines the attachments of a model. Attachment is a special type of relations created for Novius OS. See Nos\Attachment.
In Novius OS, you can configurate 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 and all relations types (has_many, belongs_to, has_one, 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;
},
);
Warning
Don’t use these relations directly, we created accessors for them.
Accessor 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);
Accessor 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->medias->summary = null; // Remove a wysiwyg from an item
// or
unset($item->wysiwygs->summary);
Returns: | Title property of model. See Model::$title_property. |
---|
Returns: | Array of possible contexts ID for current item. See Multi-Contexts. |
---|
Parameters: |
|
---|
Returns: | Prefix of column name. Computed from the primary key name (everything before the first _ character). |
---|
Returns: | Returns the item’s title, calculated from Model::$title_property. |
---|
Parameters: |
|
---|---|
Returns: | Returns the first non empty column. Will add column prefix (see Model::prefix) when needed. |