Concrete5 db.xml

Now that we know how our block gets its description and name during installation, let's check out how it builds its database table. In our basic test block, we've defined our database table as "btBasicTest." Now, open up db.xml in the block's directory. Inside, you'll find our btBasicTest database table defined as XML:

<?xml version="1.0"?>
<schema version="0.3">
<table name="btBasicTest">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="content" type="X2">
</field>
</table>
</schema>

This should be relatively easy to read: first, we define the table as named btBasicTest. Next we define our first field, which is named bID, and is an integer type. It is also defined as unsigned, and the table's primary key. Next, we have a column named "content," which is a longtext type (that's what "X2" means.)

The schema for this file is AXMLS. You can learn more about it here, including how to specify different types of columns.

One last thing: every table specified by the controller's btTable property must have bID as its primary key. This is an integer (and not set to auto_increment.) This key maps to an entry in Concrete5's core Blocks table, and is used to join your block-specific data to Concrete5 data about the block (metadata, its positioning, versions, etc…)

About Keiron

Web Developer based in the UK. Click here if you want to work with me