質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

2257閲覧

CakePHP 認証コンポーネントでエラー

takepon0209

総合スコア34

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2019/05/01 03:16

下記のサイトを参考に、Cakephpで認証コンポーネントを使ったログイン処理を作成中なのですが、エラーが出てしまいます。

https://www.ritolab.com/entry/77
https://qiita.com/yu1ro/items/5a3c81d2e705475669e9

ソース

AppController.php

php

1<?php 2namespace App\Controller; 3 4use Cake\Controller\Controller; 5use Cake\Event\Event; 6 7class AppController extends Controller 8{ 9 10 11 public function initialize() 12 { 13 parent::initialize(); 14 15 $this->loadComponent('RequestHandler', [ 16 'enableBeforeRedirect' => false, 17 ]); 18 $this->loadComponent('Flash'); 19 $this->loadComponent('Auth', [ 20 'loginAction' => [ 21 'controller' => 'Admins', 22 'action' => 'login' 23 ], 24 'loginRedirect' => [ 25 'controller' => 'Admins', 26 'action' => 'index' 27 ], 28 'logoutRedirect' => [ 29 'controller' => 'Admins', 30 'action' => 'login', 31 'home' 32 ], 33 'authenticate' => [ 34 'Form' => [ 35 'fields' => ['username' => 'username', 'password' => 'password'] 36 ] 37 ], 38 ]); 39 } 40 public function beforeFilter(Event $event) 41 { 42 $this->Auth->config('authenticate', [ 43 'Form' => ['userModel' => 'admins'], 44 ]); 45 } 46}

エラー内容

Deprecated (16384): Cake\Controller\Component\AuthComponent::config() is deprecated. Use setConfig()/getConfig() instead. - xxx/src/Controller/AppController.php, line: 80
You can disable deprecation warnings by setting Error.errorLevel to E_ALL & ~E_USER_DEPRECATED in your config/app.php. [CORE/src/Core/functions.php, line 311]

Warning (512): Unable to emit headers. Headers sent in file=xxx/vendor/cakephp/cakephp/src/Error/Debugger.php line=853 [CORE/src/Http/ResponseEmitter.php, line 51]

Warning (2): Cannot modify header information - headers already sent by (output started at xxx/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 153]

Warning (2): Cannot modify header information - headers already sent by (output started at xxx/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 185]

Warning (2): Cannot modify header information - headers already sent by (output started at xxx/vendor/cakephp/cakephp/src/Error/Debugger.php:853) [CORE/src/Http/ResponseEmitter.php, line 185]


どのように修正したらよいか教えていただきたいです。
また、 ”$this->loadComponent('Auth'…” の部分をコメントアウトすると上記のエラーは消えるので、この辺りが絡んでいるのではないかと思います。

よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Deprecated (16384): Cake\Controller\Component\AuthComponent::config() is deprecated. Use setConfig()/getConfig() instead. - xxx/src/Controller/AppController.php, line: 80

CakePHP の 3.x で書かれたコードを、その後で(composer update で)最新化したのだと思います。
その結果、非推奨になったコードが存在しているので警告が出ています。

書かれているとおりに AppController.php の 80 行目にある config() の呼び出しを、setConfig() か getConfig() を用いて書き直しましょう。

投稿2019/05/01 03:24

tacsheaven

総合スコア13703

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takepon0209

2019/05/04 01:21

ありがとうございます。 解決しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問