Klaus
January 25, 2024, 6:02pm
1
Hi,
I have a new cake application created 4.5.1
The local development is connection without problems.
On the server I get the error:
Datasource class Cake\Database\Connection could not be found
This is may config in app.php:
‘Datasources’ => [
'default' => [
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
],
In app_local.php I have entered the login data.
The first access is raising the error:
public function home() {
$this->log('PageController Home');
$catTable = TableRegistry::get('Categories');
$categorie = $catTable->find()
->where(['title' => 'Home'])
->toList();
//dd($categorie[0]->id);
$departTable =$this->getTableLocator()->get('Departments');
$newcat = $departTable->find()
->where(['title' => 'HomeNews'])
->toList();
$articles = $this->getTableLocator()->get('Articles');
$homepage = $articles->find()
->where(['category_id' => $categorie[0]->id])
->order(['department_id' => 'ASC'])
->toArray();
$news = $articles->find()
->where(['department_id' => $newcat[0]->id])
->toArray();
$this->set(compact('homepage', 'news'));
}
On this server I have two other cake application running without problems. I compared the configuration and found the onla difference:
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
But changing these settings brought no result.
Where do I have to look further? What to check?
Kind regards
Klaus
This feels weird because cakephp/src/Database/Connection.php at 4.x · cakephp/cakephp · GitHub does indeed exist.
Also the fact that you use the class constant Connection::class
means this class actually is present in your filesystem.
Maybe try giving us a full stacktrace if the error.
Klaus
January 28, 2024, 9:15am
3
Sure Kevin,
Request URL: /
Client IP: 176.199.252.125
2024-01-25 17:44:04 warning: DebugKit is disabling itself as your host cake.verein-lebensalter.de
is not in the known safe list of top-level-domains (localhost, invalid, test, example, local). If you would like to force DebugKit on use the DebugKit.forceEnable
Configure option.
2024-01-25 17:44:04 error: AppController Init
2024-01-25 17:44:04 error: PageController Init
2024-01-25 17:44:04 error: PageController Home
2024-01-25 17:44:04 error: [Cake\Datasource\Exception\MissingDatasourceException] Datasource class Cake\Database\Connection could not be found. in /var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/ConnectionRegistry.php on line 57
Exception Attributes: array (
‘class’ => ‘Cake\Database\Connection’,
‘plugin’ => NULL,
)
Stack Trace:
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Core/ObjectRegistry.php:103
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/ConnectionManager.php:214
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:255
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Datasource/Locator/AbstractLocator.php:68
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:206
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/ORM/TableRegistry.php:95
/var/www/web489/html/cakephp/src/Controller/PagesController.php:56
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/Controller.php:560
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:140
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Controller/ControllerFactory.php:115
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/BaseApplication.php:325
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:86
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php:166
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Middleware/BodyParserMiddleware.php:157
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php:189
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php:68
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php:149
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:82
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Runner.php:67
/var/www/web489/html/cakephp/vendor/cakephp/cakephp/src/Http/Server.php:99
/var/www/web489/html/cakephp/webroot/index.php:40
[main]:
Request URL: /
Client IP: 176.199.252.125
This doesn’t make sense… This would mean if you do
var_dump(class_exists('Cake\Database\Connection'));
in your AppController initialize method it would return false
- meaning something is wrong with your composer autoloader.
I’d recommend you re-install your vendor modules via
rm -rf vendor composer.lock
composer install --prefer-dist
Klaus
January 28, 2024, 1:04pm
5
Thanks Kevin,
I only made a local composer update und uploaded the vendor folder.
Additional the composer.lock , and the rror is gone.
The first upload of the application seams to produced the error.
Regards Klaus