質問編集履歴
2
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
1
|
+
`index.php`
|
2
2
|
|
3
3
|
```php
|
4
|
-
|
5
|
-
//ファイルA、B
|
6
4
|
|
7
5
|
<?php
|
8
6
|
|
@@ -18,59 +16,71 @@
|
|
18
16
|
|
19
17
|
|
20
18
|
|
21
|
-
|
19
|
+
if($app->getUserdata()->icon){
|
22
20
|
|
23
|
-
|
21
|
+
echo "◯◯";
|
24
22
|
|
25
|
-
|
23
|
+
}else {
|
26
24
|
|
27
|
-
|
25
|
+
echo "□□";
|
28
26
|
|
29
|
-
|
27
|
+
}
|
30
28
|
|
31
|
-
|
29
|
+
?>
|
32
30
|
|
33
31
|
```
|
34
32
|
|
35
|
-
|
33
|
+
`sub/index.php`
|
36
34
|
|
37
35
|
```php
|
38
36
|
|
39
|
-
//ファイルX
|
40
|
-
|
41
37
|
<?php
|
42
38
|
|
43
|
-
|
39
|
+
require_once(__DIR__ . '/../../../config/config.php');
|
44
40
|
|
45
41
|
|
46
42
|
|
47
|
-
|
43
|
+
$app = new MyApp\Controller\Index();
|
48
44
|
|
45
|
+
|
46
|
+
|
49
|
-
|
47
|
+
$app->run();
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
if($app->getUserdata()->icon){
|
52
|
+
|
53
|
+
echo "◯◯";
|
54
|
+
|
55
|
+
}else {
|
56
|
+
|
57
|
+
echo "□□";
|
50
58
|
|
51
59
|
}
|
52
60
|
|
61
|
+
?>
|
62
|
+
|
53
63
|
```
|
54
64
|
|
65
|
+
`index.php` `sub/index.php`では、`$app = new MyApp\Controller\Index();`で初期化してあり`MyApp\Controller\Index()`の関数が使えます。
|
66
|
+
|
67
|
+
`MyApp\Controller\Index()`では`extends \MyApp\Controller` で `\MyApp\Controller`そてあるので、` \MyApp\Controller`の関数も使えます。
|
68
|
+
|
69
|
+
|
70
|
+
|
55
|
-
|
71
|
+
`\MyApp\Controller`ではユーザのIDでファイルを探して、あればtrueをなければfalseを返すプログラムが実行されるようになってます。
|
56
72
|
|
57
73
|
```php
|
58
74
|
|
59
|
-
|
75
|
+
public function usericon(){
|
60
76
|
|
61
|
-
|
77
|
+
$this->setUserdata("icon", false);
|
62
|
-
|
63
|
-
{
|
64
78
|
|
65
79
|
if ($this->isLoggedIn()) {
|
66
80
|
|
67
81
|
if (file_exists("./../users/icons/" . $this->me()->id . ".png")) {
|
68
82
|
|
69
83
|
$this->setUserdata("icon", true);
|
70
|
-
|
71
|
-
}else{
|
72
|
-
|
73
|
-
$this->setUserdata("icon", false);
|
74
84
|
|
75
85
|
}
|
76
86
|
|
@@ -80,12 +90,18 @@
|
|
80
90
|
|
81
91
|
```
|
82
92
|
|
83
|
-
|
93
|
+
`index.php` `sub/index.php`を実行すると、結果上の関数が実行されます。
|
84
94
|
|
85
|
-
|
95
|
+
`index.php`ではtrueが返ってくるのですが、`sub/index.php`ではfalseが返ってきます。
|
86
96
|
|
87
|
-
ここで疑問です。まったく同じファイルを読み込んでいるのになぜtrueが返ってこないのかがわかりません。
|
88
97
|
|
89
|
-
ちなみにログインした場合にユーザのアイコンがあればtrueを返すプログラムがかいてあるところと全くおなじところに、文字列だけを返すプログラムを書いたら、A、B両方で文字列が返ってきました。
|
90
98
|
|
99
|
+
###
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
`index.php` と`sub/index.php`はディレクトリは違いますが呼び出しているファイルは同一のファイルで関数は実際呼び出されています。
|
104
|
+
|
105
|
+
上のコードの`$this->me()->id`でユーザのIDを入れているんですが、`echo $app->me()->id;`とし`index.php` `sub/index.php`それぞれで実行するとちゃんとIDがはいってきたので問題無いと思います。
|
106
|
+
|
91
|
-
|
107
|
+
ではなぜ、IDもはいっているのに画像が表示されないのでしょう?
|
1
訂
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
```php
|
4
4
|
|
5
5
|
//ファイルA、B
|
6
|
+
|
7
|
+
<?php
|
6
8
|
|
7
9
|
require_once(__DIR__ . '/../../config/config.php');
|
8
10
|
|
@@ -14,7 +16,7 @@
|
|
14
16
|
|
15
17
|
$app->run();
|
16
18
|
|
17
|
-
|
19
|
+
|
18
20
|
|
19
21
|
if($app->getUserdata()->icon){
|
20
22
|
|