Hallo zusammen,
ich versuche gerade meine lokale Erweiterung auf die in den Docs beschriebene Struktur korrekt umzubauen.
Dabei hänge ich nun an den Models, die noch nicht so wirklich wollen.
Ich habe ein Model in:
/src/Model/ProductModel.php
PHP-Code:
<?php
namespace App\Model;
use Contao\Model;
class ProductModel extends Model
{
protected static $strTable = 'tl_products';
public static function findByArtNo($val, array $opt=array()) {
$t = static::$strTable;
$objDatabase = Database::getInstance();
$objResult = $objDatabase->prepare("SELECT * FROM $t WHERE artno=?")->execute($val);
if ($objResult->numRows < 1) {
return null;
}
return static::createCollectionFromDbResult($objResult, $t);
}
}
?>
Dieses registriere ich in meiner config:
/contao/config/config.php
PHP-Code:
<?php
use App\Model\ProductModel;
// Backend Modules
array_insert($GLOBALS['BE_MOD'],1, [
'modul' => array(
'products' => array(
'tables' => array('tl_products')//,
)
)
]);
// Models
$GLOBALS['TL_MODELS']['tl_products'] = ProductModel::class;
?>
In meinem DCA /contao/dca/tl_products.php möchte ich nun auf das Model zugreifen. z.B. mit
PHP-Code:
$product = \ProductModel::findById(...);
Jedoch erhalte ich die folgende Fehlermeldung, wenn ich im Backend dann das entsprechende Modul öffne:
HTML-Code:
request.CRITICAL: Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "ProductModel" from the global namespace. Did you forget a "use" statement for "App\Model\ProductModel"?" at /var/www/vhosts/folder/var/cache/prod/contao/dca/tl_products.php line 458 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Attempted to load class \"ProductModel\" from the global namespace.\nDid you forget a \"use\" statement for \"App\\Model\\ProductModel\"? at /var/www/vhosts/folder/var/cache/prod/contao/dca/tl_products.php:458)"} []
Im DCA habe ich es bereits mit
PHP-Code:
use App\Model\ProductModel;
versucht, das hat jedoch nichts gebracht.
Wo habe ich hier etwas übersehen?
Lesezeichen