# Interacting with components in the cake console REPL

**URL:** <https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876>\
**Category:** Need Help\
**Created:** [November 2, 2021, 9:32am UTC](https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876 "2021-11-02T09:32:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![namatoj](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/namatoj/32/2173_2.png) [@namatoj](https://discourse.cakephp.org/u/namatoj)\
**Post date:** [November 2, 2021, 9:32am UTC](https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876/1 "2021-11-02T09:32:27Z")

</div>

Hi!

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

I open the cake shell using

```auto
# bin/cake console

```

in my terminal.

I am able to get load a table using

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

```

And then interact with it as mentioned here [Interactive Console (REPL) - 4.x](https://book.cakephp.org/4/en/console-commands/repl.html)

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:

```auto
project_root_dir/src/Controller/Component/MyComponent.php

```

Any advice is greatly appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [November 3, 2021, 4:00am UTC](https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876/2 "2021-11-03T04:00:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![namatoj](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/namatoj/32/2173_2.png) [@namatoj](https://discourse.cakephp.org/u/namatoj)\
**Post date:** [November 3, 2021, 11:59am UTC](https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876/3 "2021-11-03T11:59:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [November 4, 2021, 10:50pm UTC](https://discourse.cakephp.org/t/interacting-with-components-in-the-cake-console-repl/9876/4 "2021-11-04T22:50:50Z")

</div>

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 😉

[![](https://img.youtube.com/vi/z3E_UdH1XeE/maxresdefault.jpg "CakeFest Virtual 2021 Day 2 - How to re use code: Utility Classes and PHP Namespaces - Kevin Pfeifer") ](https://www.youtube.com/watch?v=z3E_UdH1XeE)
