Model

class Nos\Orm\Model

Extends Model of FuelPHP ORM.

Configuration

property Nos\Orm\Model::$title_property
Defines the title property of a model. Can be a column name or a closure (which take current $iitem as parameter).
If not defined, automatically set to first column which has title, label or name in its name, or (as last resort) the first varchar.
property Nos\Orm\Model::$behaviours

Defines the behaviours of model. Same syntax as observers.

property Nos\Orm\Model::$attachment

Defines the attachments of a model. Attachment is a special type of relations created for Novius OS. See Nos\Attachment.

Examples

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;
        },
);

Relations

property Nos\Orm\Model::$linked_wysiwygs
property Nos\Orm\Model::$linked_medias

Warning

Don’t use these relations directly, we created accessors for them.

Accessors

property Nos\Orm\Model::$medias

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->media = $Model_Media; // Set a Model_Media named 'cv'
property Nos\Orm\Model::$wysiwygs

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', width content 'foo'.

Methods

static Nos\Orm\Model::title_property
Returns:Title property of model. See Model::$title_property.
static Nos\Orm\Model::behaviours($specific = null, $default = null)
Nos\Orm\Model::get_possible_context()
Returns:Array of possible contexts ID for current item. See Multi-Contexts.
static Nos\Orm\Model::add_properties($properties)
Parameters:
  • $properties (array) – Additional properties (merged).
static 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:
  • $column (array) – A column name.
Returns:

Returns the first non empty column. Will add column prefix (see Model::prefix) when needed.