Skip to content
flack edited this page Dec 8, 2016 · 5 revisions

Midgard Schema is a data abstraction system which is used to define data structures in XML files. Each MgdSchema class corresponds to one table in the database. The rows of the table can be accessed as native objects in PHP with Metadata attached.

MgdSchema XML structure

MgdSchema XML definitions include information about fieldnames (which are available as object attributes) and the corresponding data types. Aside from that, they can mark fields as links (allowing querying by linked constraints) and they can also include hierarchic information, i.e. tree structures. Here's for example the (slightly shortened) MgdSchema for midgard_article:

<type name="midgard_article" table="article" parent="midgard_topic">
    <property name="id" type="unsigned integer" primaryfield="id">
        <description>Local non-replication-safe database identifier</description>
    </property>
    <property name="name" type="string" index="yes">
        <description>URL name of the article</description>
    </property>
    <property name="extra1" type="string">
        <description>Extra string field</description>
    </property>
    <property name="extra2" type="string">
        <description>Extra string field</description>
    </property>
    <property name="extra3" type="string">
        <description>Extra string field</description>
    </property>
    <property name="type" type="integer" index="yes">
        <description>Type of the article</description>
    </property>
    <property name="up" type="unsigned integer" link="midgard_article:id" upfield="up">
        <description>Possible prior part of the article</description>
    </property>
    <property name="topic" type="unsigned integer" link="midgard_topic:id" parentfield="topic">
        <description>Topic the article is under</description>
    </property>
    <property name="title" type="string">
        <description>Title of the article</description>
    </property>
    <property name="abstract" type="text">
        <description>Short abstract of the article</description>
    </property>
    <property name="content" type="text">
        <description>Content of the article</description>
    </property>
    <property name="url" type="string" index="yes">
        <description>External URL of the article</description>
    </property>
    <property name="lang" type="unsigned integer" link="midgard_language:id">
        <description>Language the article is in</description>
    </property>
</type>

Once this MgdSchema is read by the system, it will provide the midgard_article PHP class, which you can use to interact with the data:

$article = new midgard_article($id);
echo '<h1>' . $article->title . '</h1>';
$article->abstract = 'My first article';
$article->update();

Usage

Query Builder or Midgard Collector are used to retrieve MgdSchema objects from the database. Midgard Reflection is available for writing Schema agnostic applications like Asgard.

Availability

In standard Midgard installations, at least these MgdSchemas are available:

They are defined in the file MgdObjects.xml

Links

http://www.midgard-project.org/documentation/mgdschema/

http://www.midgard-project.org/documentation/mgdschema-file-properties/

http://www.midgard-project.org/documentation/mgdschema-in-php/

Clone this wiki locally