Unknown method called on Cake\ORM\Table - CakePHP 4

Hi,

I’ve been developing with CakePHP 2 for years and recently jumped to 4, and it’s a big change. But, got my app working nicely locally and deployed it to a testing server. Locally I’m on a Mac running XAMPP without any issues. The deployment server is Fedora 31 running PHP 7.3. Everything seems set up correctly, I’ve tested the database connection too.

But, when I load my site, I get the following error:

Unknown method “parameters” called on Cake\ORM\Table

But it works fine locally. I’ve checked everything. Re-run composer on the deployment server. Checked requirements.The files are synced with Git. But, I cannot figure out why I’m getting this error.

The file referenced in the error looks like this:

AppController.php

namespace App\Controller;
use Cake\Controller\Controller;
use Cake\ORM\TableRegistry;
use Cake\Core\Configure;
use App\Application;

class AppController extends Controller {
    public function initialize(): void {
        parent::initialize();

		$this->App = new Application(dirname(dirname(__DIR__)) . '/config');
		$this->requester = $this->App->requester();
...
        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');

	$this->Babel 			= TableRegistry::getTableLocator()->get('babel');
	$this->Brands 			= TableRegistry::getTableLocator()->get('brands');
	$this->Collections 		= TableRegistry::getTableLocator()->get('collections');
...
	$this->Odin = TableRegistry::getTableLocator()->get('odin');
	

		$requestparams = $this->request->getAttribute('params');

		$this->params = $this->Odin->parameters($requestparams);
...

I’d really appreciate it if someone could help me figure out why I get this error on one server but not the other. Am I missing something in the set up that isn’t synced over Git? Is there a file I need to manually add to the server? I feel if this was the case it would just crash.

Anyway, all help gratefully received.

Thanks,

Michael

1 Like

FYI, the parameters() method is part of a Parameters Behavior which is loaded in the OdinTable.

Check the type of $this->Odin. I’m betting it’s a generic Cake table object, not your specific class. That’ll most likely be because of case differences in the file system, if your dev system is Windows and live is Linux.

Genius! Didn’t even consider case differences.

From local Mac:

object(App\Model\Table\OdinTable) {

	'registryAlias' => 'odin',
	'table' => 'odin',
	'alias' => 'odin',
	'entityClass' => 'App\Model\Entity\Odin',
	'associations' => [],
	'behaviors' => [
		(int) 0 => 'Parameters',
		(int) 1 => 'Arraysearch',
		(int) 2 => 'File'
	],
	'defaultConnection' => 'default',
	'connectionName' => 'default'

}

From Fedora server:

object(Cake\ORM\Table) {

	'registryAlias' => 'odin',
	'table' => 'odin',
	'alias' => 'odin',
	'entityClass' => 'Cake\ORM\Entity',
	'associations' => [],
	'behaviors' => [],
	'defaultConnection' => 'default',
	'connectionName' => 'default'

}

After sorting out the cases on all the classes I pinpointed the error:

->getTableLocator()->get(‘odin’);

should be

->getTableLocator()->get(‘Odin’);

Odd thig is when I first used the table locator I copied and pasted the method from the CakePHP Cookbook!

Thanks so much for your help, I really appreciate it.

Kind regards,

Michael