質問編集履歴
2
ソースの追加について
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,9 +28,13 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
|
31
|
+
ディレクトリは```config```、```lib```、```public_html```となっております。
|
32
|
+
|
33
|
+
|
34
|
+
|
32
|
-
|
35
|
+
```php
|
36
|
+
|
33
|
-
public_html/index.php
|
37
|
+
// public_html/index.php
|
34
38
|
|
35
39
|
<?php
|
36
40
|
|
@@ -106,11 +110,13 @@
|
|
106
110
|
|
107
111
|
</html>
|
108
112
|
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
|
109
|
-
|
117
|
+
```php
|
110
|
-
|
111
|
-
|
112
|
-
|
118
|
+
|
113
|
-
lib/Controller/index.php
|
119
|
+
// lib/Controller/index.php
|
114
120
|
|
115
121
|
<?php
|
116
122
|
|
@@ -150,4 +156,70 @@
|
|
150
156
|
|
151
157
|
}
|
152
158
|
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
```php
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
// config/config.php
|
170
|
+
|
171
|
+
<?php
|
172
|
+
|
173
|
+
ini_set('display_errors', 1);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
define('DSN', 'mysql:host=**********;dbname=**********;charset=utf8');
|
178
|
+
|
153
|
-
|
179
|
+
define('DB_USERNAME', '**********');
|
180
|
+
|
181
|
+
define('DB_PASSWORD', '**********');
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST']);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
require_once(__DIR__ . '/../lib/functions.php');
|
190
|
+
|
191
|
+
require_once(__DIR__ . '/autoload.php');
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
session_start();
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
```php
|
200
|
+
|
201
|
+
// config/autoload.php
|
202
|
+
|
203
|
+
<?php
|
204
|
+
|
205
|
+
spl_autoload_register(function($class) {
|
206
|
+
|
207
|
+
$prefix = 'MyApp\\';
|
208
|
+
|
209
|
+
if (strpos($class, $prefix) === 0) {
|
210
|
+
|
211
|
+
$className = substr($class, strlen($prefix));
|
212
|
+
|
213
|
+
$classFilePath = __DIR__ . '/../lib/' . str_replace('\\', '/', $className) . '.php';
|
214
|
+
|
215
|
+
if (file_exists($classFilePath)) {
|
216
|
+
|
217
|
+
require $classFilePath;
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
```
|
1
ソースの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,3 +17,137 @@
|
|
17
17
|
ちなみに、ローカル開発環境はVAGRANTでcentosを立ち上げて行っています。
|
18
18
|
|
19
19
|
さくらのレンタルサーバにてPHPのバーションは5.6.18です。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
申し訳ございません。うっかりして会員限定のページだったことに気づきませんでした。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
public_html/index.php =============================
|
34
|
+
|
35
|
+
<?php
|
36
|
+
|
37
|
+
// ユーザーの一覧
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
require_once(__DIR__ . '/../config/config.php');
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
// var_dump($_SESSION['me']);
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
$app = new MyApp\Controller\Index();
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
$app->run();
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
// $app->me()
|
58
|
+
|
59
|
+
// $app->getValues()->users
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
?>
|
64
|
+
|
65
|
+
<!DOCTYPE html>
|
66
|
+
|
67
|
+
<html lang="ja">
|
68
|
+
|
69
|
+
<head>
|
70
|
+
|
71
|
+
<meta charset="utf-8">
|
72
|
+
|
73
|
+
<title>Home</title>
|
74
|
+
|
75
|
+
<link rel="stylesheet" href="styles.css">
|
76
|
+
|
77
|
+
</head>
|
78
|
+
|
79
|
+
<body>
|
80
|
+
|
81
|
+
<div id="container">
|
82
|
+
|
83
|
+
<form action="logout.php" method="post" id="logout">
|
84
|
+
|
85
|
+
<?= h($app->me()->email); ?> <input type="submit" value="Log Out">
|
86
|
+
|
87
|
+
<input type="hidden" name="token" value="<?= h($_SESSION['token']); ?>">
|
88
|
+
|
89
|
+
</form>
|
90
|
+
|
91
|
+
<h1>Users <span class="fs12">(<?= count($app->getValues()->users); ?>)</span></h1>
|
92
|
+
|
93
|
+
<ul>
|
94
|
+
|
95
|
+
<?php foreach ($app->getValues()->users as $user) : ?>
|
96
|
+
|
97
|
+
<li><?= h($user->email); ?></li>
|
98
|
+
|
99
|
+
<?php endforeach; ?>
|
100
|
+
|
101
|
+
</ul>
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
</body>
|
106
|
+
|
107
|
+
</html>
|
108
|
+
|
109
|
+
==========================================================
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
lib/Controller/index.php =============================
|
114
|
+
|
115
|
+
<?php
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
namespace MyApp\Controller;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
class Index extends \MyApp\Controller {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public function run() {
|
128
|
+
|
129
|
+
if (!$this->isLoggedIn()) {
|
130
|
+
|
131
|
+
// login
|
132
|
+
|
133
|
+
header('Location: ' . SITE_URL . '/test/login.php');
|
134
|
+
|
135
|
+
exit;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
// get users info
|
142
|
+
|
143
|
+
$userModel = new \MyApp\Model\User();
|
144
|
+
|
145
|
+
$this->setValues('users', $userModel->findAll());
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
==========================================================
|