Getting associated models with $this->Auth in Cakephp

前端 未结 3 743
太阳男子
太阳男子 2021-02-20 10:07

I am using CakePHP 2.0\'s integrated Auth component. I have the following tables :

  • Users
  • Groups
  • Profiles
3条回答
  •  失恋的感觉
    2021-02-20 10:37

    Two ways:

    1) Extend the FormAuthenticate class (see /Controller/Component/Auth) or whatever you use to login and override the _findUser() method and tell the Auth component to use this authorize class. See this page how to do all of that http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

    2) Simply implement a method in the model that will fetch all data you want and call it in the login method of your controller and write the data into the session. IMO it is handy to have such a method because sometimes you need to refresh the session data anyways.

    Because of your comment on the other answer:

    You will have to write a method and some code in a model that will return you the data. CakePHP can't read your mind and a database without code. No matter which of both suggested ways you're going to use, you'll have to write code.

提交回复
热议问题