前提・実現したいこと
PHPでログイン機能を実装しています。
"ドットインストール"の内容です。
「PHPでログイン機能を実装しよう:#08 ログイン画面を作っていこう」
Webサーバにアクセスしようとしたところ、以下のようなエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Fatal error: Class 'MyApp\Controller\Index' not found in /home/vagrant/sns_php/public_html/index.php on line 7
該当のソースコード
PHP
1//vagrant/sns_php/public_html/index.php 2 3<?php 4 5require_once(__DIR__ . '/../config/config.php'); 6 7$app = new MyApp\Controller\Index(); 8 9$app->run();
PHP
1//vagrant/sns_php/lib/Controller/index.php 2 3<?php 4 5namespace MyApp\Controller; 6 7class Index extends \MyApp\Controller { 8 9 public function run() { 10 if (!$this->isLoggedIn()) { 11 // login 12 header('Location: ' . SITE_URL . '/login.php'); 13 exit; 14 } 15 } 16 17} 18
PHP
1//vagrant/sns_php/config/autoload.php 2 3<?php 4 5/* 6MyApp 7index.php controller 8MyApp\Controller\Index 9-> lib/Controller/Index.php 10*/ 11 12spl_autoload_register(function($class) { 13 $prefix = 'MyApp\'; 14 if (strpos($class, $prefix) === 0) { 15 $className = substr($class, strlen($prefix)); 16 $classFilePath = __DIR__ . '/../lib/' . str_replace('\', '/', $className) . '.php'; 17 if (file_exists($classFilePath)) { 18 require $classFilePath; 19 } 20 } 21});
$ php -S 192.168.33.10:8000 -t public_html/
試したこと
ドットインストールの通りに行っています。
補足情報(FW/ツールのバージョンなど)
CyberDock、Atomを利用
回答1件
あなたの回答
tips
プレビュー