Last active
June 22, 2017 04:28
-
-
Save konnoyosuke/bccc8e6f12826f8345572e96757e3e49 to your computer and use it in GitHub Desktop.
AutoComponentとCustom Finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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