Use footprint across plugins
I have split my application into plugins .
Im trying to use Footprint and I have the following setup:
- I have
FootprintAwareTraitcalled insidesrc/Controller/AppController - I have my
TablesandModelsinsrcandControllersandTemplatesinplugins/Foo.
The above setup didn't work.
So I left FootprintAwareTrait; inside src/Controller/AppController and tried to move some stuff around:
- Moved everything in
src- WORKED - Moved everything in
plugins/MyPluginName- WORKED
But I still want to have Tables and Models in src and Controllers and Templates in plugins/Foo, so any ideas if it's possible to use the Footprintplugin in that case ?
I have managed to reproduce that in a new project and made a repo.
Add debug(get_class($this->Footprints)); to index() method of TestPlugin/src/Controller/FootprintsController.php. What output do you get?
I got this one as output:
'Cake\ORM\Table'
So you see a Table instance is used (which doesn't have Footprint behavior attached) since you don't have a table class for that model in your plugin.
Is that intended by design? Because that (models in src and the rest in a plugin) works for all other plugins including the Blame one.
@kristiyandobrev, cake automatically creates a table for you when a class (file) couldn't be found for the table you want to instantiate. When doing so, it doesn't attach any plugin's behavior/listener by default.
If you want you Footprints controller in plugin to use Footprints model from main app you will have to explicitly call $this->loadModel('Footprints') else by default it will always try to load Footprints.Footprints model from your plugin.
@ADmad Where should I call $this->loadModel('Footprints') ? If I call it in the @initialize where I normally load my models it doesn't work ?
Do it in beforeFilter() instead of initialize(). Instead of explicit loading you can also try setting $modelClass property of controller to Footprints. If you need more assistance please use the cakephp forum or IRC / Slack not this issues tracker.
Why would the plugin require loading tables in the beforeFilter() rather than initialize() ? 😄