I have two controllers UsersController and UserRolesController. I want load the UserRoles model into my UsersController for fetching the value of the users with their roles. Can anyone help me on this.

1 Answers

0
Shudhansh Shekhar On Best Solutions

You can do that in multiple ways.

  • In your UsersController, put $this->loadModel('UserRoles') before the code and use it like $this->UserRoles->whatevermethod.

  • Inject TableRegistry as use Cake\ORM\TableRegistry; ( if not already injected ) at the top of UsersController.

    Use the model like : TableRegistry::get('UserRoles)->whatevermethod