Open Source Content Management System

Midgard core - how to read API

  1. Conventions
    1. Object constructor
    2. Setting and getting property
    3. Invoking methods
    4. Destroying object

This part of core manual is addressed for developers who write applications using languages like PHP. The idea is to help understanding Midgard internals if some features are not ducumented in higher levels API and are documented in core API. It should be also very helpfull for those who want to learn how midgard-core is designed by reading its source code.

Conventions

Midgard core is built on top of GLib libraries and uses GObjects as data structures for object oriented programming wherever it is possible.

Read Gobject conventions to understand examples.

Remember that unlike in languages like PHP , midgard core object methods always use object's pointer as a reference to itself.

Object constructor

midgard-php

$article = new midgard_article();

midgard-core

MgdObject *article = midgard_object_new(mgd, "midgard_article");

You can ignore first argument , which is connection handler and is not used in midgard-core objects API except object constructor which assigns connection hanlder for new object instance and hides it for an API.

Setting and getting property

midgard-php

$article->title = "MyTitle";

echo "Article created with $article->title title!";

midgard-core

gchar *title_string;
g_object_set(G_OBJECT(article), "title", "MyTitle", NULL);

g_object_get(G_OBJECT(article), "title", &title_string, NULL);
g_printf("Article created with %s title", title_string);

Invoking methods

midgard-php

$article->create();

midgard-core

midgard_object_create(article);

Destroying object

midgard-php

unset($article);

midgard-core

g_object_unref(G_OBJECT(article));
Designed by Nemein, hosted by Anykey