Your own model class is ready to use after the following three steps:
// contao/dca/tl_example.php
$GLOBALS['TL_DCA']['tl_example'] = [
…
];
See the DCA documentation and the DCA reference for more information.
The naming convention for the model class is to omit tl_
, convert the snake_case to PascalCase and add “Model”.
// src/Model/ExampleModel.php
namespace App\Model;
use Contao\Model;
/**
* add properties for IDE support
*
* @property string $hash
*/
class ExampleModel extends Model
{
protected static $strTable = 'tl_example';
// if you have logic you need more often, you can implement it here
public function setHash()
{
$this->hash = md5($this->id);
}
}
// contao/config/config.php
use App\Model\ExampleModel;
$GLOBALS['TL_MODELS']['tl_example'] = ExampleModel::class;
Now you’re done and can use your own Model class!