Bahlul Siddiquee
Bahlul Siddiquee

Reputation: 303

How can i load model into the different controller

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

Answers (1)

Shudhansh Shekhar
Shudhansh Shekhar

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

Related Questions