質問編集履歴
2
ソースの追加について
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,8 +13,10 @@
|
|
13
13
|
|
14
14
|
申し訳ございません。うっかりして会員限定のページだったことに気づきませんでした。
|
15
15
|
|
16
|
+
ディレクトリは```config```、```lib```、```public_html```となっております。
|
16
17
|
|
18
|
+
```php
|
17
|
-
public_html/index.php
|
19
|
+
// public_html/index.php
|
18
20
|
<?php
|
19
21
|
// ユーザーの一覧
|
20
22
|
|
@@ -52,9 +54,10 @@
|
|
52
54
|
</div>
|
53
55
|
</body>
|
54
56
|
</html>
|
55
|
-
|
57
|
+
```
|
56
58
|
|
59
|
+
```php
|
57
|
-
lib/Controller/index.php
|
60
|
+
// lib/Controller/index.php
|
58
61
|
<?php
|
59
62
|
|
60
63
|
namespace MyApp\Controller;
|
@@ -74,4 +77,37 @@
|
|
74
77
|
}
|
75
78
|
|
76
79
|
}
|
80
|
+
```
|
81
|
+
|
82
|
+
|
83
|
+
```php
|
84
|
+
|
85
|
+
// config/config.php
|
86
|
+
<?php
|
87
|
+
ini_set('display_errors', 1);
|
88
|
+
|
89
|
+
define('DSN', 'mysql:host=**********;dbname=**********;charset=utf8');
|
77
|
-
|
90
|
+
define('DB_USERNAME', '**********');
|
91
|
+
define('DB_PASSWORD', '**********');
|
92
|
+
|
93
|
+
define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST']);
|
94
|
+
|
95
|
+
require_once(__DIR__ . '/../lib/functions.php');
|
96
|
+
require_once(__DIR__ . '/autoload.php');
|
97
|
+
|
98
|
+
session_start();
|
99
|
+
```
|
100
|
+
```php
|
101
|
+
// config/autoload.php
|
102
|
+
<?php
|
103
|
+
spl_autoload_register(function($class) {
|
104
|
+
$prefix = 'MyApp\\';
|
105
|
+
if (strpos($class, $prefix) === 0) {
|
106
|
+
$className = substr($class, strlen($prefix));
|
107
|
+
$classFilePath = __DIR__ . '/../lib/' . str_replace('\\', '/', $className) . '.php';
|
108
|
+
if (file_exists($classFilePath)) {
|
109
|
+
require $classFilePath;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
});
|
113
|
+
```
|
1
ソースの更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,4 +7,71 @@
|
|
7
7
|
自分なりにいろいろと調べてみたのですが、解決方法が見当たらないため、ご教授いただけますでしょうか。
|
8
8
|
|
9
9
|
ちなみに、ローカル開発環境はVAGRANTでcentosを立ち上げて行っています。
|
10
|
-
さくらのレンタルサーバにてPHPのバーションは5.6.18です。
|
10
|
+
さくらのレンタルサーバにてPHPのバーションは5.6.18です。
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
申し訳ございません。うっかりして会員限定のページだったことに気づきませんでした。
|
15
|
+
|
16
|
+
|
17
|
+
public_html/index.php =============================
|
18
|
+
<?php
|
19
|
+
// ユーザーの一覧
|
20
|
+
|
21
|
+
require_once(__DIR__ . '/../config/config.php');
|
22
|
+
|
23
|
+
// var_dump($_SESSION['me']);
|
24
|
+
|
25
|
+
$app = new MyApp\Controller\Index();
|
26
|
+
|
27
|
+
$app->run();
|
28
|
+
|
29
|
+
// $app->me()
|
30
|
+
// $app->getValues()->users
|
31
|
+
|
32
|
+
?>
|
33
|
+
<!DOCTYPE html>
|
34
|
+
<html lang="ja">
|
35
|
+
<head>
|
36
|
+
<meta charset="utf-8">
|
37
|
+
<title>Home</title>
|
38
|
+
<link rel="stylesheet" href="styles.css">
|
39
|
+
</head>
|
40
|
+
<body>
|
41
|
+
<div id="container">
|
42
|
+
<form action="logout.php" method="post" id="logout">
|
43
|
+
<?= h($app->me()->email); ?> <input type="submit" value="Log Out">
|
44
|
+
<input type="hidden" name="token" value="<?= h($_SESSION['token']); ?>">
|
45
|
+
</form>
|
46
|
+
<h1>Users <span class="fs12">(<?= count($app->getValues()->users); ?>)</span></h1>
|
47
|
+
<ul>
|
48
|
+
<?php foreach ($app->getValues()->users as $user) : ?>
|
49
|
+
<li><?= h($user->email); ?></li>
|
50
|
+
<?php endforeach; ?>
|
51
|
+
</ul>
|
52
|
+
</div>
|
53
|
+
</body>
|
54
|
+
</html>
|
55
|
+
==========================================================
|
56
|
+
|
57
|
+
lib/Controller/index.php =============================
|
58
|
+
<?php
|
59
|
+
|
60
|
+
namespace MyApp\Controller;
|
61
|
+
|
62
|
+
class Index extends \MyApp\Controller {
|
63
|
+
|
64
|
+
public function run() {
|
65
|
+
if (!$this->isLoggedIn()) {
|
66
|
+
// login
|
67
|
+
header('Location: ' . SITE_URL . '/test/login.php');
|
68
|
+
exit;
|
69
|
+
}
|
70
|
+
|
71
|
+
// get users info
|
72
|
+
$userModel = new \MyApp\Model\User();
|
73
|
+
$this->setValues('users', $userModel->findAll());
|
74
|
+
}
|
75
|
+
|
76
|
+
}
|
77
|
+
==========================================================
|