'Cakephp database session
I am trying to configure database session, so I added these lines to app.php
'Session' => [
'defaults' => 'database',
'timeout' => 8032,
'cookieTimeout' => 10 * 8032,
],
And I have created the database table:
CREATE TABLE `sessions` (
`id` char(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
`created` datetime DEFAULT CURRENT_TIMESTAMP, -- optional, requires MySQL 5.6.5+
`modified` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- optional, requires MySQL 5.6.5+
`data` blob DEFAULT NULL, -- for PostgreSQL use bytea instead of blob
`expires` int(10) unsigned
DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
But I still get this error:
Fatal error: [Cake\ORM\Exception\MissingTableClassException] Table class for alias
Sessionscould not be found
What am I doing wrong?
MORE INFORMATION
CAKEPHP VERSION: 4.2.3
StackTrace
[Cake\ORM\Exception\MissingTableClassException] Table class for alias `Sessions` could not be found. (/var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php:245) #0
/var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/Datasource/Locator/AbstractLocator.php(62): Cake\ORM\Locator\TableLocator->createInstance('Sessions', Array)
#1 /var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/ORM/Locator/TableLocator.php(205): Cake\Datasource\Locator\AbstractLocator->get('Sessions', Array)
#2 /var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/Http/Session/DatabaseSession.php(62): Cake\ORM\Locator\TableLocator->get('Sessions', Array)
#3 /var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/Http/Session.php(274): Cake\Http\Session\DatabaseSession->__construct(Array)
#4 /var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/sr in /var/www/vhosts/domain/ShopManagment/vendor/cakephp/cakephp/src/Error/ErrorHandler.php on line 196
Solution 1:[1]
Notice that the directions say there is a schema for the Sessions table included with the CakePHP files. Double check that your schema is correct for the version of Cake you're using. Make sure you can log into MySQL and browse that table.
Also, are there any associations created with this Session table? Because the alias problem often lies with association arrays?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tom Belknap |
