Open Source Content Management Framework

MidCOM 2.5 Datamanager Rewrite Example usage code

  1. Simple usage using the simple controller
  2. Using the Datamanager standalone

This is a MidCOM 2.5 Development Technical Note covering the Datamanger Rewrite. Everything written here is subject to change without notice.

The following examples outline common usage scenarios of the datamanager, allowing you to start testing and hacking with it. It is recommended that you read the notes about Schema Definition and the Example Schema.

Simple usage using the simple controller

$article = new midcom_db_article($id);

$controller = midcom_helper_datamanager2_controller::create('simple');
$controller->load_schemadb($test_schema_db);
$controller->set_storage($article);
$controller->initialize();

echo "Process form returned: " . $controller->process_form() . "\n";

$controller->display_form();

Where $id obiviously is a valid Midgard Article ID or GUID, and $test_schema_db is either an path to a file/snippet or a raw schema array.

Using the Datamanager standalone

If you just want to handle the data for display, you can break it down to the actual data management code, skipping everything else:

$the_db = midcom_helper_datamanager2_schema::load_database($test_schema_db);
$article = new midcom_db_article($id);

$dm = new midcom_helper_datamanager2_datamanager($the_db);
$dm->set_schema();
$dm->set_storage($article);

foreach ($dm->schema->field_order as $name)
{
    echo "{$name}: ";
    switch ($dm->schema->fields[!!$name][!!'type'])
    {
        default:
            print_r($dm->types[$name]->value);
            break;

        case 'select':
            print_r($dm->types[$name]->selection);
            print_r($dm->types[$name]->others);
            break;
    }
}
Designed by Nemein, hosted by Kafit