Interacting with components in the cake console REPL


I am trying to debug an issue I am having using the cake console REPL with little success.

I open the cake shell using

# bin/cake console

in my terminal.

I am able to get load a table using

>>> $my_table = Cake\Datasource\FactoryLocator::get('Table')->get('MyTableName');

And then interact with it as mentioned here Interactive Console (REPL) - 4.x

But I have a component that is misbehaving and I would like to call functions on my component from the REPL to debug and interact with the results. But how do I access components (and controllers) in the REPL? I can’t figure it out and I am not very familiar with the inner workings of CakePHP and PHP.

The path to my component is:


Any advice is greatly appreciated.

Components only work correctly when they are initialized with a controller. If you can, I think you’d be better served by setting up xdebug instead of using the console like this.

Thank you for your response.

I’ll have a look at xdebug.

Do you know if it is possible to load a Controller, as opposed to a Component, in the REPL?

Instead of putting re-usable code parts inside components you should rather use more generic php classes (some call it utility classes, some call it service classes)

As Zuluru already said Components only work (and are only meant) to be used inside controllers, not anywhere else.

Shameless plug for my video from the last cakefest event :wink:

1 Like