CakePhp: organizza i controller nelle sottocartelle
-
27-10-2019 - |
Domanda
È possibile in CakePHP organizzare controller (e modelli) nelle sottocartelle? Grazie.
Soluzione
Sì, puoi, ma è deprecato. Vedere la discussione qui. L'ultimo post in questa pagina descrive come farlo nel bootstrap.
Altri suggerimenti
Non è affatto deprecato. Puoi raggiungere questo obiettivo usando l'app: Build e punta alle tue sottocartelle. Ad esempio, se vuoi mettere tutti i tuoi modelli Twitter nel modello/Twitter per organizzare il tuo codice, puoi aggiungere quanto segue al bootstrap.php
:
App::build(array(
'Model' => array(APP . 'Model' . DS . 'Twitter' . DS),
));
Ora, qualsiasi file di modello che inserisce nel modello/Twitter sarà disponibile quando lo chiami.
Vedi di più qui: http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#app::build
For those of you looking for a CakePhp3 version of this answer here is a link to the routing documentation. Use router prefixing that matches your controller sub-namespaces / directory structure.
http://book.cakephp.org/3.0/en/development/routing.html#prefix-routing
In CakePHP 3 you can define additional class paths in your composer.json (see http://book.cakephp.org/3.0/en/development/configuration.html#additional-class-paths)
Btw if you want to organize your template files in subfolders you have to add their paths in your app.php at App.paths
http://book.cakephp.org/3.0/en/development/configuration.html#general-configuration
Just in case someone else is searching for this piece of information... ;)