Getting associated models with $this->Auth in Cakephp

前端 未结 3 745
太阳男子
太阳男子 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:35

    As far as I'm aware the Auth component only caches the data from your Users model. You can use that information to retrieve the desired data from the other models, by for example using this in your controller:

    $group_data = $this->Group->findById($this->Auth->user('group_id'));
    

    Or

    $profile_data = $this->Profile->findByUserId($this->Auth->user('id'));
    

    But I don't think you can get it from the Auth component directly, as it doesn't cache the related model data out of the box.

提交回复
热议问题