Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CakePHP 3 – 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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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 { ... }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading