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
Dieses registriere ich in meiner config: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);
}
}
?>
/contao/config/config.php
In meinem DCA /contao/dca/tl_products.php möchte ich nun auf das Model zugreifen. z.B. mitPHP-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;
?>Jedoch erhalte ich die folgende Fehlermeldung, wenn ich im Backend dann das entsprechende Modul öffne:PHP-Code:$product = \ProductModel::findById(...);
Im DCA habe ich es bereits mitHTML-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)"} []versucht, das hat jedoch nichts gebracht.PHP-Code:use App\Model\ProductModel;
Wo habe ich hier etwas übersehen?

Zitieren
