9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP3での認証テーブルの変更

Posted at

cakePHPでは認証に使うテーブルはデフォルトではusersになっていて、
たまに別テーブルを使いたい時がありますね。
え?無いですか?私はあったのでメモします

検証済みバージョン

Cakephp 3.1.3

解決策

変更したいテーブル名をMembersとすると
こんな感じでした。

AppController.php
    public function beforeFilter(Event $event)
    {
        $this->Auth->config('authenticate', [
            'Form' => ['userModel' => 'Members'],
        ]);
    }

##未検証
他の解決策としては
個別に書くなら

AppController.php
$this->Auth->config('authenticate', [
    'Basic' => ['userModel' => 'Members'],
    'Form' => ['userModel' => 'Members']
]);

まとめて書くなら

AppController.php
$this->Auth->config('authenticate', [
    AuthComponent::ALL => ['userModel' => 'Members'],
    'Basic',
    'Form'
]);

らしいですが、未検証です。
あっていたらご報告お待ちしております。

参考サイト

公式ドキュメント

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?