Reputation: 303
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.
Upvotes: 1
Views: 96
Reputation: 720
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
Upvotes: 1