お世話になっております
今dotinstallで勉強中です。
PHPでログイン機能を実装しよう https://dotinstall.com/lessons/sns_php_v3/35826
これの23章目ぐらいからUncaught Errorが出てしまい正しくブラウザ表示がしないです
mysql:5.6.37 PHP:7.1.10
************************************************************
Error内容
1[Mon Apr 2 09:15:55 2018] PHP Fatal error: Uncaught Error: Class 'MyApp\Controller\Index' not found in /home/vagrant/sns_php/public_html/index.php:9 2Stack trace: 3#0 {main} 4 thrown in /home/vagrant/sns_php/public_html/index.php on line 9 5[Mon Apr 2 09:15:55 2018] 192.168.33.1:49567 [200]: / - Uncaught Error: Class 'MyApp\Controller\Index' not found in /home/vagrant/sns_php/public_html/index.php:9 6Stack trace: 7#0 {main} 8 thrown in /home/vagrant/sns_php/public_html/index.php on line 9
public_html/index。php
1 2<?php 3 4// ユーザーの一覧 5 6require_once(__DIR__ . '/../config/config.php'); 7 8// var_dump($_SESSION['me']); 9 10$app = new MyApp\Controller\Index(); 11 12$app->run(); 13 14// $app->me() 15// $app->getValues()->users 16 17?> 18<!DOCTYPE html> 19<html lang="ja"> 20<head> 21 <meta charset="utf-8"> 22 <title>Home</title> 23 <link rel="stylesheet" href="styles.css"> 24</head> 25<body> 26 <div id="container"> 27 <form action="logout.php" method="post" id="logout"> 28 <?= h($app->me()->email); ?> <input type="submit" value="Log Out"> 29 <input type="hidden" name="token" value="<?= h($_SESSION['token']); ?>"> 30 </form> 31 <h1>Users <span class="fs12">(<?= count($app->getValues()->users); ?>)</span></h1> 32 <ul> 33 <?php foreach ($app->getValues()->users as $user) : ?> 34 <li><?= h($user->email); ?></li> 35 <?php endforeach; ?> 36 </ul> 37 </div> 38</body> 39</html> 40
config.php
1<?php 2 3ini_set('display_errors', 1); 4 5define('DSN', 'mysql:dbhost=localhost;dbname=dotinstall_sns_php'); 6define('DB_USERNAME', 'dbuser'); 7define('DB_PASSWORD', 'muku1130'); 8 9define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST']); 10 11require_once(__DIR__ . '/../lib/functions.php'); 12require_once(__DIR__ . '/autoload.php'); 13 14session_start(); 15
Controller/index.php
1<?php 2 3namespace MyApp\Controller; 4 5class Index extends \MyApp\Controller { 6 7 public function run() { 8 if (!$this->isLoggedIn()) { 9 // login 10 header('Location: ' . SITE_URL . '/login.php'); 11 exit; 12 } 13 14 // get users info 15 $userModel = new \MyApp\Model\User(); 16 $this->setValues('users', $userModel->findAll()); 17 } 18 19}
よろしくご指導下さい
回答1件
あなたの回答
tips
プレビュー