contao/issues — Issue #86: Add oncreate_callback() to DC_Table.php
Author: importer
Created: 2011-11-24 09:13:28+00:00
State: open
Labels: Feature, framework

I've noticed that several extensions use the table mapping idea. Catalog, FormAuto and other modules (not published yet, upcoming private e-commerce solution).

They all use the technique to interrupt the constructor of DC_Table and change the tablename dynamically. This allows these applications to have 1 DCA interface which is dynamically changed, including the TABLENAME. Even though the DCA is called tl_catalog_items its actually editing a table name retrieved dynamically from the database at runtime.

Since this cannot be performed in the onload_callback, which only runs AFTER the constructor is run, I suggest adding another callback, as done in my own universal driver below.

The callback must return the "new" tablename which is then provided to the regular constructor.

```
require_once 'DC_Table.php';

class DC_DynamicTable extends DC_Table
{

public function +construct($strTable)
{

// HOOK: add custom create function
if (array_key_exists('oncreate_callback', $GLOBALS['TL_DCA'][$strTable]['config']) && is_array($GLOBALS['TL_DCA'][$strTable]['config']['oncreate_callback']))
{
foreach ($GLOBALS['TL_DCA'][$strTable]['config']['oncreate_callback'] as $callback)
{
$this->import($callbackr0);
$strTable = $this->$callbackr0->$callbackr1($strTable);
}
}

parent::__construct($strTable);
}
}
```

--- _Originally created by thyon on September 11th, 2008, at 08:57pm (ID 86)_