現在ネットの情報からcakephp4でログイン認証機能を作ろうと試みております。そこで
src/application.phpにて
php
1use Cake\Core\Configure; 2use Cake\Core\ContainerInterface; 3use Cake\Core\Exception\MissingPluginException; 4use Cake\Datasource\FactoryLocator; 5use Cake\Error\Middleware\ErrorHandlerMiddleware; 6use Cake\Http\BaseApplication; 7use Cake\Http\Middleware\BodyParserMiddleware; 8use Cake\Http\Middleware\CsrfProtectionMiddleware; 9use Cake\Http\MiddlewareQueue; 10use Cake\ORM\Locator\TableLocator; 11use Cake\Routing\Middleware\AssetMiddleware; 12use Cake\Routing\Middleware\RoutingMiddleware; 13use Authentication\AuthenticationService; 14use Authentication\AuthenticationServiceInterface; 15use Authentication\AuthenticationServiceProviderInterface; 16use Authentication\Middleware\AuthenticationMiddleware; 17use Cake\Routing\Router; 18use Psr\Http\Message\ServerRequestInterface; 19/** 20 * Application setup class. 21 * 22 * This defines the bootstrapping logic and middleware layers you 23 * want to use in your application. 24 */ 25class Application extends BaseApplication implements AuthenticationServiceProviderInterface 26{ 27 //ネットに書いてある処理 28}
このように記載したところ
Fatal error: Uncaught Error: Interface 'Authentication\AuthenticationServiceProviderInterface' not found in /var/www/html/sample/src/Application.php:43 Stack trace: #0 /var/www/html/sample/vendor/composer/ClassLoader.php(444): include() #1 /var/www/html/sample/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/html/s...') #2 [internal function]: Composer\Autoload\ClassLoader->loadClass('App\Application') #3 /var/www/html/sample/webroot/index.php(37): spl_autoload_call('App\Application') #4 {main} thrown in /var/www/html/sample/src/Application.php on line 43
このようなエラーメッセージが吐かれます。
自分の考えだとエラーの原因は最初に読み込んだAuthenticationプラグインの場所が悪いからだと思い、cakephpプラジェクトのrootディレクトリについて調べたのですが、ネットで調べてもいまいちcakephpプラジェクトのrootディレクトリというのがどこにあるのか分かりません。もしよければcakephpプラジェクトのrootディレクトリというものがどこを指示しているのか。このエラーメッセージの原因は何なのか。この二点をご教授して頂きたいです。
宜しくお願い致します。
参考にしたサイト↓↓↓↓↓↓↓↓↓↓
CakePHP 4 で Authentication プラグインを使ってユーザー認証を実装
CakePHP4でブログサイト作るチュートリアル
CakePHP4でログイン、ログアウトを実装する
CakePHP4を試す
composer.jsonファイル
php
1{ 2 "name": "cakephp/app", 3 "description": "CakePHP skeleton app", 4 "homepage": "https://cakephp.org", 5 "type": "project", 6 "license": "MIT", 7 "require": { 8 "php": ">=7.2", 9 "cakephp/cakephp": "~4.2.0", 10 "cakephp/migrations": "^3.0", 11 "cakephp/plugin-installer": "^1.3", 12 "mobiledetect/mobiledetectlib": "^2.8" 13 }, 14 "require-dev": { 15 "cakephp/bake": "^2.3", 16 "cakephp/cakephp-codesniffer": "~4.2.0", 17 "cakephp/debug_kit": "^4.4", 18 "josegonzalez/dotenv": "^3.2", 19 "phpunit/phpunit": "~8.5.0 || ^9.3", 20 "psy/psysh": "@stable" 21 }, 22 "suggest": { 23 "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.", 24 "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan/Psalm compatibility.", 25 "phpstan/phpstan": "PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code." 26 }, 27 "autoload": { 28 "psr-4": { 29 "App\": "src/" 30 } 31 }, 32 "autoload-dev": { 33 "psr-4": { 34 "App\Test\": "tests/", 35 "Cake\Test\": "vendor/cakephp/cakephp/tests/" 36 } 37 }, 38 "scripts": { 39 "post-install-cmd": "App\Console\Installer::postInstall", 40 "post-create-project-cmd": "App\Console\Installer::postInstall", 41 "check": [ 42 "@test", 43 "@cs-check" 44 ], 45 "cs-check": "phpcs --colors -p src/ tests/", 46 "cs-fix": "phpcbf --colors -p src/ tests/", 47 "stan": "phpstan analyse", 48 "test": "phpunit --colors=always" 49 }, 50 "prefer-stable": true, 51 "config": { 52 "sort-packages": true 53 } 54}
あなたの回答
tips
プレビュー