Footprint icon indicating copy to clipboard operation
Footprint copied to clipboard

Use footprint across plugins

Open kristiyandobrev opened this issue 10 years ago • 9 comments

I have split my application into plugins .

Im trying to use Footprint and I have the following setup:

  • I have FootprintAwareTrait called inside src/Controller/AppController
  • I have my Tables and Models in src and Controllers and Templates in plugins/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.

kristiyandobrev avatar Jun 29 '16 10:06 kristiyandobrev

Add debug(get_class($this->Footprints)); to index() method of TestPlugin/src/Controller/FootprintsController.php. What output do you get?

ADmad avatar Jun 29 '16 13:06 ADmad

I got this one as output:

'Cake\ORM\Table'

kristiyandobrev avatar Jun 29 '16 13:06 kristiyandobrev

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.

ADmad avatar Jun 29 '16 13:06 ADmad

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 avatar Jun 29 '16 15:06 kristiyandobrev

@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.

jadb avatar Jun 30 '16 05:06 jadb

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 avatar Jun 30 '16 06:06 ADmad

@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 ?

kristiyandobrev avatar Jun 30 '16 07:06 kristiyandobrev

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.

ADmad avatar Jun 30 '16 07:06 ADmad

Why would the plugin require loading tables in the beforeFilter() rather than initialize() ? 😄

Spriz avatar Jun 30 '16 08:06 Spriz