Skip to content

Instantly share code, notes, and snippets.

@konnoyosuke
Last active June 22, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konnoyosuke/bccc8e6f12826f8345572e96757e3e49 to your computer and use it in GitHub Desktop.
Save konnoyosuke/bccc8e6f12826f8345572e96757e3e49 to your computer and use it in GitHub Desktop.
AutoComponentとCustom Finder
<?php
// AppController function initialize()
$this->Auth->config('authenticate', [
'Form' => [
'userModel' => 'Employees',
'finder' => ['auth' => [$this->request->getData()]],
'fields' => [
'username' => 'code',
'password' => 'encrypted_password',
],
],
]);
// EmployeeTable.php にfindAuthを追加する
// 企業コードを使って認証をする。 EmployeeとCompanyはアソシエーションされている
public function findAuth(\Cake\ORM\Query $query, array $options)
{
$query
->select(['id', 'code', 'encrypted_password'])
->where(['Companies.code' => $options[0]['Companies']['code']])
->contain(['Companies']);
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment