CakePHP3 Auth Question


#1

So I am working with my auth component and it appears to be returning my users table just fine. However my users table has linkings to other tables. When a user logs in how can I pull in the supporting linking table information. For instance in my table the “role” column shows a 1 but in another table 1 is Field Engineer. How do I link them and have all of the data available to me?

Brian


#2

You will have to create a custom finder method

in your user table you must add something like this:

public function findAuth(\Cake\ORM\Query $query, array $options)
{
    $query
        ->select(['id', 'username', 'password'])
        ->where(['Users.active' => 1])
        ->contain('Roles');

    return $query;
}

and add this method to your finder

    'authenticate' => [
        'Form' => [
            'finder' => 'auth'
        ]
    ],

with 'auth' been the name of your finder method.

https://book.cakephp.org/3.0/en/controllers/components/authentication.html#customizing-find-query


#3

Thanks much! This did the trick!