Organizing Table Classes in Folders



I have a lot of Table Classes in my project.
I would like to organize the classes files by folder (Users, Stats, etc)
I have one class under src/Model/Table/Stats/BlockedTable.php

namespace App\Model\Table\Stats;
use Cake\ORM\Table;
class BlockedTable extends Table
{ …

If I do:

Blockquote TableRegistry::get(‘Blocked’);

Just getting an instance of


I tried to add to the composer.json and then running composer dumpautoload

"App\Model\Table\Stats\": “src/Model/Table/Stats”,
“App\”: “src”,

but still getting the same Cake\ORM\Table class

How should I do it?


If I do:

TableRegistry::get('Blocked', ['className' => 'App\Model\Table\Stats\BlockedTable']);

Then it works.

Is there a way to configure CakePHP so I do not have to specify the className every time? :roll_eyes::roll_eyes::roll_eyes:

PD: Using className there is no need to modifiy the composer.json


You can group models/controllers/shells in plugins (using bake).
So you could create a plugin Supplies and to use it in the rest:


But! I don’t know (I didn’t try yet) is how to link from the plugin to the base App.
Lets say you got the table Contractors and is used in several tables/plugins, if you keep ContractorsTable in the main App in the plugin you can’t call “belongsTo”, so you should make a BasePlugins for the core models. Just my opinion