Model

class 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_null key to true if you want that this property stores a null value when it receives empty string.

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.

property Nos\Orm\Model::$shared_wysiwygs_context

Array of WYSIWYG keys which are shared by context twins. See WYSIWYG accessor.

property Nos\Orm\Model::$shared_medias_context

Array of media keys which are shared by context twins. See Media accessor.

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, shared_wysiwygs_context, shared_medias_context 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).

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 = $Model_Media; // Attach a Model_Media named 'cv'

$item->medias->cv = null; // Detach a media from an item
// or
unset($item->medias->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', with content 'foo'.

$item->medias->summary = null; // Remove a wysiwyg from an item
// or
unset($item->wysiwygs->summary);

Methods

static Nos\Orm\Model::title_property
Returns:Title property of model. See Model::$title_property.
static Nos\Orm\Model::table
Returns:The DB table name of model.
static Nos\Orm\Model::behaviours($specific = null, $default = null)
static Nos\Orm\Model::add_properties($properties)
Parameters:
  • $properties (array) – Additional properties (merged).
static Nos\Orm\Model::addRelation($type, $name, array $options = array())

Add a relation to model

Parameters:
  • $type (string) – A valid relation type.
  • $name (string) – The relation name to add.
  • $options (string) – The relation options
Throws:

\FuelException if $type is not a valid one.

static Nos\Orm\Model::configModel
Returns:Array configurations of the model.
static 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:
  • $method (string) – Name of the event, also name of the method Behaviours.
  • $args (array) – Arguments of the event.
static Nos\Orm\Model::eventStatic($method, $args = array())

Trigger an event (caught by behaviours) on the model class.

Parameters:
  • $method (string) – Name of the event, also name of the method Behaviours.
  • $args (array) – Arguments of the event.
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.

Read the Docs v: dubrovka
Versions
latest
elche
dubrovka
chiba.2
chiba.1
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.