# CakeDC/Users Call to undefined method App\\Controller\\CustomUsersController::getUsersTable()

**URL:** <https://discourse.cakephp.org/t/cakedc-users-call-to-undefined-method-app-controller-customuserscontroller-getuserstable/12216>\
**Category:** Need Help\
**Created:** [August 31, 2024, 6:16am UTC](https://discourse.cakephp.org/t/cakedc-users-call-to-undefined-method-app-controller-customuserscontroller-getuserstable/12216 "2024-08-31T06:16:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmcmonagle](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jmcmonagle](https://discourse.cakephp.org/u/jmcmonagle)\
**Post date:** [August 31, 2024, 6:16am UTC](https://discourse.cakephp.org/t/cakedc-users-call-to-undefined-method-app-controller-customuserscontroller-getuserstable/12216/1 "2024-08-31T06:16:09Z")

</div>

I am just starting with a CakePHP 5 development and have installed the CakeDC/Users plugin.

I wanted to test extending the plugin and thought I’d followed the instructions and I can access the login page without an issue. However, whenever I attempt to access the “register” page, for which I wanted to use the plugin method, I receive a “Call to undefined method App\Controller\CustomUsersController::getUsersTable()” error, which is coming from the plugin and I can see exists as a method in the UsersController class.

My code is:

**Bootstrap method in Application.php**

> ```
> public function bootstrap(): void
> {
> // Call parent to load bootstrap from files.
> parent::bootstrap();
> 
> if (PHP_SAPI !== 'cli') {
> FactoryLocator::add(
> 'Table',
> (new TableLocator())->allowFallbackClass(false)
> );
> }
> 
> Configure::write('DebugKit.ignoreAuthorization', true);
> $this->addPlugin(Plugin::class);
> Configure::write('Users.config', ['users']);
> }
> 
> ```

**Changes to users.php**

> $config = [  
> ‘Users’ =\> [  
> // Table used to manage users  
> ‘table’ =\> ‘CustomUsers’,  
> // Controller used to manage users plugin features & actions  
> ‘controller’ =\> ‘CustomUsers’,

**CustomUsersController**

> namespace App\Controller;
> 
> use CakeDC\Users\Controller\Traits\LoginTrait;  
> use CakeDC\Users\Controller\Traits\RegisterTrait;
> 
> class CustomUsersController extends AppController  
> {  
> use LoginTrait;  
> use RegisterTrait;
> 
> ```
> /**
> * @return void
> * @throws \Exception
> */
> public function initialize(): void
> {
> parent::initialize();
> $this->loadComponent('CakeDC/Users.Setup');
> if ($this->components()->has('Security')) {
> $this->Security->setConfig(
> 'unlockedActions',
> [
> 'login',
> 'register',
> ]
> );
> }
> }
> 
> ```
> 
> }

**plugins.php**

> return [  
> // Plugins only needed when in debug mode  
> ‘DebugKit’ =\> [‘onlyDebug’ =\> true],
> 
> ```
> // Optional plugins which are only needed in CLI commands
> 'Bake' => ['onlyCli' => true, 'optional' => true],
> 
> // Required plugins only in CLI commands
> 'Migrations' => ['onlyCli' => true],
> 
> // Add your custom plugins here
> 'CakeDC/Users' => ['routes' => true, 'bootstrap' => true],
> 
> ```
> 
> ];

**Added following to permissions.php**

> ```
> [
> 'role' => '*',
> 'plugin' => null,
> 'controller' => 'CustomUsers',
> 'action' => ['register', 'login'],
> 'bypassAuth' => true,
> ],
> 
> ```

The only difference I can see from what is in the docs is the use of plugins.php to load the plugin instead of explicitly loading it.

Also, I can get it to work when I change CustomUsersController to extend UsersController instead of AppController, which makes sense since the getUserTable method is in the UsersController. Is it an error in the plugin docs as extending the plugin table and entity classes require extending the plugin classes rather than the base Table or Entity class.

Any advice greatly appreciated.

---

<div class="post-metadata">

**Author:** ![jmcd73](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jmcd73/32/481_2.png) [@jmcd73](https://discourse.cakephp.org/u/jmcd73)\
**Post date:** [August 31, 2024, 7:21am UTC](https://discourse.cakephp.org/t/cakedc-users-call-to-undefined-method-app-controller-customuserscontroller-getuserstable/12216/2 "2024-08-31T07:21:56Z")

</div>

Possibly because you are extending `CustomUsers` off `AppController`.

You might need to extend it off `\CakeDC\Users\Controller\UsersController`  
or  
include a `use CustomUsersTableTrait;` statement in your `CustomUsersController` which will give you the `getUsersTable()` method that is missing

e.g

```php
class CustomUsersController extends 
    \CakeDC\Users\Controller\UsersController
{
//...

```

or

```php
use CakeDC\Users\Controller\Traits\LoginTrait;
use CakeDC\Users\Controller\Traits\RegisterTrait;
use CakeDC\Users\Controller\Traits\CustomUsersTableTrait;
class CustomUsersController extends AppController
{
use LoginTrait;
use RegisterTrait;
use CustomUsersTableTrait;

/**

```

---

<div class="post-metadata">

**Author:** ![jmcmonagle](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jmcmonagle](https://discourse.cakephp.org/u/jmcmonagle)\
**Post date:** [August 31, 2024, 8:43am UTC](https://discourse.cakephp.org/t/cakedc-users-call-to-undefined-method-app-controller-customuserscontroller-getuserstable/12216/3 "2024-08-31T08:43:47Z")

</div>

Thanks @jmcd73.

Adding the “use CustomUsersTableTrait” as per your suggestion has it working for me now so I’ll move on with that approach.

Much appreciated.

For completeness, I did have it working when I extended off of UsersController but the docs for CakeDC/Users gives the code below as the example for extending the controller so thought there might be a reason for extending off of AppController and wanted to try and get it working in line with the docs.

The code I pasted above didn’t include all the “use” statements from below but it still didn’t work for me even when I copied this code (changing “MyUsersTable” to “CustomUsersTable”) so maybe a documentation error.

> namespace App\Controller;
> 
> use App\Controller\AppController;  
> use App\Model\Table\MyUsersTable;  
> use Cake\Event\Event;  
> use CakeDC\Users\Controller\Traits\LoginTrait;  
> use CakeDC\Users\Controller\Traits\RegisterTrait;
> 
> class MyUsersController extends AppController  
> {  
> use LoginTrait;  
> use RegisterTrait;
> 
> ```
> /**
> * Initialize
> *
> * @return void
> */
> public function initialize(): void
> {
> parent::initialize();
> $this->loadComponent('CakeDC/Users.Setup');
> if ($this->components()->has('Security')) {
> $this->Security->setConfig(
> 'unlockedActions',
> [
> 'login',
> 'webauthn2faRegister',
> 'webauthn2faRegisterOptions',
> 'webauthn2faAuthenticate',
> 'webauthn2faAuthenticateOptions',
> ]
> );
> }
> }
> 
> //add your new actions, override, etc here
> 
> ```
> 
> }
