Open Source Content Management System

MgdSchema in PHP - Object constructor

  1. Create "empty" object instance with default properties
  2. Create object instance which should be fetched from database "by id".
  3. Create object instance which should be fetched from database "by guid".

new class_name([mixed])

Constructor for MgdSchema objects is exactly the same as described in PHP.

Since Midgard version 1.8 , objects' constructor has optional id or guid parameter. When integer parameter is used then object is fetched by id property. When string parameter is used then object is fetched by guid from database.

If passed parameter is integer or string type , then internal function isguid is called to determine if object should be fetched by guid or by id. There is no need to type cast numeric values as such types are internally type casted to integer.Even if they come from argc or REQUEST array.

Object constructor returns FALSE when object's record(s) can not be fetched by particular id or guid ( however type of returned value is Object ). Check for created object's instance may be done with simple control structure:

<?php
$article = new midgard_article("BadGuidWithSome12345");
if(!$article)
    echo "Couldn't create midgard_article object instance!";
?>

E_NOTICE error is logged when other types ( like array or object ) are passed as constructor parameter.

Examples for MgdSchema type midgard_topic.

Create "empty" object instance with default properties

<?php
$object = new midgard_topic();  
?>

Returned $object will have all properties set to their default values.

Create object instance which should be fetched from database "by id".

<?php
$object = new midgard_topic(1);  
?>

This is equivalent to:

 get_by_id(1);
     ?>

Create object instance which should be fetched from database "by guid".

<?php
$object = new midgard_topic("37cb0d47f718665fd02e3fe16f6c487e");  
?>

This is equivalent to:

 get_by_guid("37cb0d47f718665fd02e3fe16f6c487e");
     ?>
Designed by Nemein, hosted by Anykey