Open Source Content Management System

PHP midgard object parameters

  1. Methods

This part of API is forward compatible and it's recommended for Midgard 1.9/2.0. This is experimental section.

Midgard uses object parameters to attach named values to any Midgard object. The parameters are grouped into parameter domains which are freely chooseable strings.

Parameters focus on three main types: domain, name and value. Domain groups many parameters, name defines unique parameter in a group ( domain ) and value holds any value ( of string type ) which is associated with particular domain and name.

MgdSchema allows you to define any database' table structure storage for objects, however your application might need to extend object only in few cases, so parameters are best solution for such purpose. Table structure doesn't have to be changed and object may be extended at any time.

Let's say you created an object about car, and you need to extend this object ( among hundreds of others not extended) to provide car's speed, weight and height. All you need is domain "car" ( you may want to name it differently ) , names: "speed", "weight" and "height". And their values of course. An example code will look like this:

<?php

$object = new midgard_article($guid);
$object->set_parameter("car", "speed", "200km/h");
$object->set_parameter("car", "height", "1,5m");
$object->set_parameter("car", "weight", "500kg");
?>

Now, when object is extended and parameters are created, you can fetch their values:

<?php

$object = new midgard_article($guid);
$speed = $object->get_parameter("car", "speed");
$height = $object->get_parameter("car", "height");
$weight = $object->get_parameter("car", "weight");

?>

Parameters are represented by midgard_parameter class, but API methods provides caching functionality and faster implementation. All parameters are associated with objects ( parents ) with parentguid property which holds parent object's guid value.

Methods

Designed by Nemein, hosted by Anykey