Using 'contain()' in the AuthComponent array to specify fields

后端 未结 2 1297
生来不讨喜
生来不讨喜 2021-01-25 21:31

In CakePHP\'s documentation I\'ve seen from version 2.2 has been added the configuration key \'contain\' for the AuthComponent:

The core authentication ob

相关标签:
2条回答
  • 2021-01-25 22:05

    you were almost there. Just add the "fields" key on your first example, like this :

    'Auth' => array(
        'authenticate'      => array(
            'Form' => array(
                'contain'   => array('User' => array('fields'=>array('id', 'full_name'))),
                'fields'    => array('username' => 'email'),
            )
        )
    )
    

    NB : while this is syntaxically correct, I do not see why 'User' should contain 'User'... well YMMV

    0 讨论(0)
  • 2021-01-25 22:25

    Contain() is used to contain a DIFFERENT model, not the same one Auth is already retrieving (unless you're trying to contain other User's ie their friends or something - but then you'd likely have an alias, and not 'User').

    So, an example would be:

    'Auth' => array(
        'authenticate'      => array(
            'Form' => array(
                'contain'   => array('Post'),
                'fields'    => array('username' => 'email'),
            )
        )
    )
    

    Which would then cause Auth to retreive the user's Posts as well when it retrieves the user's data.

    0 讨论(0)
提交回复
热议问题