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 name="name" type="string" index="yes">
        <description>URL name of the article</description>
    <property name="extra1" type="string">
        <description>Extra string field</description>
    <property name="extra2" type="string">
        <description>Extra string field</description>
    <property name="extra3" type="string">
        <description>Extra string field</description>
    <property name="type" type="integer" index="yes">
        <description>Type of the article</description>
    <property name="up" type="unsigned integer" link="midgard_article:id" upfield="up">
        <description>Possible prior part of the article</description>
    <property name="topic" type="unsigned integer" link="midgard_topic:id" parentfield="topic">
        <description>Topic the article is under</description>
    <property name="title" type="string">
        <description>Title of the article</description>
    <property name="abstract" type="text">
        <description>Short abstract of the article</description>
    <property name="content" type="text">
        <description>Content of the article</description>
    <property name="url" type="string" index="yes">
        <description>External URL of the article</description>
    <property name="lang" type="unsigned integer" link="midgard_language:id">
        <description>Language the article is in</description>

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';


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.


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

They are defined in the file MgdObjects.xml


Clone this wiki locally