简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM