cakephp-3.0cakephp-model

Where to locate code to be used by many Model->Tables. Can't find AppModel


Looking for AppModel to create a function that would be used by many different Tables.

Since AppModel doesn't seem to exist anymore, where do I put common functions for Tables, like I use AppController for all my controllers?

Thanks in advance for any assistance.


Solution

  • It isn't needed by everyone, so it's gone away, but you can resurrect it in your project. Nothing magic about it, just standard PHP inheritance. Create an AppTable class in the Tables folder, extending the standard Table class:

    namespace App\Model\Table;
    use Cake\ORM\Table;
    class AppTable extends Table { ... }
    

    and change your various tables to extend that class instead of Table:

    namespace App\Model\Table;
    class UsersTable extends AppTable { ... }