質問編集履歴

3

コードの追加

2019/04/27 05:38

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
File without changes
test CHANGED
@@ -46,17 +46,175 @@
46
46
 
47
47
  $menuName = $_GET['name'];
48
48
 
49
-
49
+ ----------------------------------------------------------------------------------------
50
50
 
51
51
  $menu = Product::findByName($products,$menuName);
52
52
 
53
- <!--ここで名前を判断していると考えております。
53
+ <!--ここで名前を判断していると考えております。-->
54
54
 
55
55
  ----------------------------------------------------------------------------------------
56
56
 
57
+ ?>
58
+
59
+
60
+
61
+ <!DOCTYPE html>
62
+
63
+ <html>
64
+
65
+ <head>
66
+
67
+ <meta charset="utf-8">
68
+
57
-   findByNameの定義 ↓(promenu.php)変数は全てprivate指定しております。
69
+ <title>Product page</title>
70
+
58
-
71
+ <link rel="stylesheet" type="text/css" href="show.css">
72
+
73
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
74
+
75
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
76
+
77
+ <link href='https://fonts.googleapis.com/css?family=Pacifico|Lato' rel='stylesheet' type='text/css'>
78
+
79
+ <link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet">
80
+
81
+ </head>
82
+
83
+
84
+
85
+ <body>
86
+
87
+ <header>
88
+
89
+ <img class="basket" src="http://illustrain.com/img/work/2016/illustrain02-shopping07.png">
90
+
91
+ <p class="title">Shopping basket</p>
92
+
93
+ <p class="sabtitle">商品注文ページ</p>
94
+
95
+ </header>
96
+
97
+
98
+
99
+ <form action="lastconfirm.php" method="post">
100
+
101
+ <div class="product-wrapper">
102
+
103
+ <div class="container">
104
+
105
+ <img class="product-image" src="<?php echo $menu->getImage() ?>">
106
+
107
+ <div class="top-right">
108
+
109
+ <p class="product-name"><?php echo $menu->getName() ?></p>
110
+
111
+ <p class="product-price">¥<?php echo $menu->getPrice() ?> (税込)</p>
112
+
113
+ <div class="top-amount">
114
+
115
+ <span class="font">数量</span>
116
+
117
+ <input class="product-amount" type="text" name="<?php echo $menu->getName() ?>" value="0">
118
+
119
+ <span class="font">個</span>
120
+
121
+ </div>
122
+
123
+ <input class="product-decision" type="submit" value="注文を確定する">
124
+
125
+ </div>
126
+
127
+ </div>
128
+
129
+ <div class="clear"></div>
130
+
131
+ </div>
132
+
133
+ </form>
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+ </body>
142
+
143
+ </html>
144
+
145
+
146
+
147
+ ```
148
+
149
+ ```php
150
+
151
+ <?php
152
+
153
+
154
+
155
+ class Product {
156
+
157
+ private $date;
158
+
159
+ private $image;
160
+
161
+ private $name;
162
+
163
+ private $price;
164
+
165
+ public $orderCount = 0;
166
+
167
+
168
+
169
+
170
+
171
+ public function __construct($date,$image,$name,$price) {
172
+
173
+ $this->date = $date;
174
+
175
+ $this->image = $image;
176
+
177
+ $this->name = $name;
178
+
179
+ $this->price = $price;
180
+
181
+ }
182
+
183
+
184
+
185
+ public function getDate() {
186
+
187
+ return $this->date;
188
+
189
+ }
190
+
191
+
192
+
193
+ public function getImage() {
194
+
195
+ return $this->image;
196
+
197
+ }
198
+
199
+
200
+
201
+ public function getName() {
202
+
203
+ return $this->name;
204
+
205
+ }
206
+
207
+
208
+
209
+ public function getPrice() {
210
+
211
+ return $this->price;
212
+
213
+ }
214
+
215
+ ----------------------------------------------------------------------------------------------
216
+
59
-    public static function findByName($menus,$name) {
217
+ public static function findByName($menus,$name) {
60
218
 
61
219
  foreach($menus as $menu) {
62
220
 
@@ -70,178 +228,106 @@
70
228
 
71
229
  }
72
230
 
73
- ---------------------------------------------------------------------------------------------
231
+ -----------------------------------------------------------------------------------------------
232
+
233
+ public function getOrderCount() {
234
+
235
+ return $this->orderCount;
236
+
237
+ }
238
+
239
+
240
+
241
+ public function setOrderCount($orderCount) {
242
+
243
+ $this->orderCount = $orderCount;
244
+
245
+
246
+
247
+ }
74
248
 
75
249
  ?>
76
250
 
77
-
78
-
79
- <!DOCTYPE html>
80
-
81
- <html>
82
-
83
- <head>
84
-
85
- <meta charset="utf-8">
86
-
87
- <title>Product page</title>
88
-
89
- <link rel="stylesheet" type="text/css" href="show.css">
90
-
91
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
92
-
93
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
94
-
95
- <link href='https://fonts.googleapis.com/css?family=Pacifico|Lato' rel='stylesheet' type='text/css'>
96
-
97
- <link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet">
98
-
99
- </head>
100
-
101
-
102
-
103
- <body>
104
-
105
- <header>
106
-
107
- <img class="basket" src="http://illustrain.com/img/work/2016/illustrain02-shopping07.png">
108
-
109
- <p class="title">Shopping basket</p>
110
-
111
- <p class="sabtitle">商品注文ページ</p>
112
-
113
- </header>
114
-
115
-
116
-
117
- <form action="lastconfirm.php" method="post">
118
-
119
- <div class="product-wrapper">
120
-
121
- <div class="container">
122
-
123
- <img class="product-image" src="<?php echo $menu->getImage() ?>">
124
-
125
- <div class="top-right">
126
-
127
- <p class="product-name"><?php echo $menu->getName() ?></p>
128
-
129
- <p class="product-price">¥<?php echo $menu->getPrice() ?> (税込)</p>
130
-
131
- <div class="top-amount">
132
-
133
- <span class="font">数量</span>
134
-
135
- <input class="product-amount" type="text" name="<?php echo $menu->getName() ?>" value="0">
136
-
137
- <span class="font">個</span>
138
-
139
- </div>
140
-
141
- <input class="product-decision" type="submit" value="注文を確定する">
142
-
143
- </div>
144
-
145
- </div>
146
-
147
- <div class="clear"></div>
148
-
149
- </div>
150
-
151
- </form>
152
-
153
-
154
-
155
-
251
+ ```
252
+
253
+ ```php
254
+
255
+
256
+
257
+ <!--lastconfirm.php(値を受けて表示するファイル)-->
258
+
259
+
260
+
261
+  <body>
262
+
263
+ <div class="confirm-wrapper">
264
+
265
+ <?php foreach($products as $product) :?>
266
+
267
+ <?php
268
+
269
+ $orderCount = filter_input(INPUT_POST,$product->getName());
270
+
271
+     
272
+
273
+      echo $product->getName();
274
+
275
+ echo $orderCount;
276
+
277
+ echo $product->getPrice();
278
+
279
+
280
+
281
+ ?>
282
+
283
+ <?php endforeach ?>
156
284
 
157
285
 
158
286
 
159
287
  </body>
160
288
 
161
- </html>
162
-
163
-
164
-
165
289
  ```
166
290
 
167
291
  ```php
168
292
 
169
-
170
-
171
- <!--lastconfirm.php(値を受けて表示するファイル)-->
293
+ <!--prodata.php(インスタンスのファイル)-->
172
-
173
-
174
-
175
-  <body>
294
+
176
-
177
- <div class="confirm-wrapper">
295
+   
178
-
179
- <?php foreach($products as $product) :?>
296
+
180
-
181
- <?php
297
+   <?php
298
+
182
-
299
+ require_once('promenu.php');
300
+
301
+
302
+
303
+
304
+
305
+ $alfort = new Product('New','画像URL ','アルフォート(20枚入)',307);
306
+
307
+ $calpas = new Product('New','画像URL ','徳用カルパス',377);
308
+
309
+ $lumand = new Product('Sold out','画像URL ','ルマンド(3袋入)',315);
310
+
311
+ $country = new Product('New','画像URL ','カントリーマーム(チョコ&バニラ)',370);
312
+
313
+ $oreo = new Product('A few','画像URL ','OREO 1箱(2袋入)',191);
314
+
315
+ $happy = new Product('New','画像URL ','ハッピーターン(3袋入)',691);
316
+
317
+
318
+
183
- $orderCount = filter_input(INPUT_POST,$product->getName());
319
+ $products = array($alfort,$calpas,$lumand,$country,$oreo,$happy);
184
-
185
-     
186
-
187
-      echo $product->getName();
320
+
188
-
189
- echo $orderCount;
321
+
190
-
191
- echo $product->getPrice();
322
+
192
-
193
-
194
-
323
+
324
+
195
- ?>
325
+ ?>
196
-
197
- <?php endforeach ?>
326
+
198
-
199
-
200
-
201
- </body>
327
+
202
328
 
203
329
  ```
204
330
 
205
- ```php
206
-
207
- <!--prodata.php(インスタンスのファイル)-->
208
-
209
-   
210
-
211
-   <?php
212
-
213
- require_once('promenu.php');
214
-
215
-
216
-
217
-
218
-
219
- $alfort = new Product('New','画像URL ','アルフォート(20枚入)',307);
220
-
221
- $calpas = new Product('New','画像URL ','徳用カルパス',377);
222
-
223
- $lumand = new Product('Sold out','画像URL ','ルマンド(3袋入)',315);
224
-
225
- $country = new Product('New','画像URL ','カントリーマーム(チョコ&バニラ)',370);
226
-
227
- $oreo = new Product('A few','画像URL ','OREO 1箱(2袋入)',191);
228
-
229
- $happy = new Product('New','画像URL ','ハッピーターン(3袋入)',691);
230
-
231
-
232
-
233
- $products = array($alfort,$calpas,$lumand,$country,$oreo,$happy);
234
-
235
-
236
-
237
-
238
-
239
- ?>
240
-
241
-
242
-
243
- ```
244
-
245
331
 
246
332
 
247
333
  ●試したこと

2

findByname()の定義部分を表示しました。

2019/04/27 05:38

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
File without changes
test CHANGED
@@ -34,96 +34,214 @@
34
34
 
35
35
  <!--show.php(値を送信するファイルで、商品ごとにページを用意しています。)-->
36
36
 
37
+   <?php
38
+
39
+
40
+
41
+ require_once('prodata.php');
42
+
43
+ require_once('promenu.php');
44
+
45
+
46
+
47
+ $menuName = $_GET['name'];
48
+
49
+
50
+
51
+ $menu = Product::findByName($products,$menuName);
52
+
53
+ <!--ここで名前を判断していると考えております。
54
+
55
+ ----------------------------------------------------------------------------------------
56
+
57
+   findByNameの定義 ↓(promenu.php)変数は全てprivate指定しております。
58
+
59
+    public static function findByName($menus,$name) {
60
+
61
+ foreach($menus as $menu) {
62
+
63
+ if($menu->getName() == $name) {
64
+
65
+ return $menu;
66
+
67
+ }
68
+
69
+ }
70
+
71
+ }
72
+
73
+ ---------------------------------------------------------------------------------------------
74
+
75
+ ?>
76
+
77
+
78
+
79
+ <!DOCTYPE html>
80
+
81
+ <html>
82
+
83
+ <head>
84
+
85
+ <meta charset="utf-8">
86
+
87
+ <title>Product page</title>
88
+
89
+ <link rel="stylesheet" type="text/css" href="show.css">
90
+
91
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
92
+
93
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
94
+
95
+ <link href='https://fonts.googleapis.com/css?family=Pacifico|Lato' rel='stylesheet' type='text/css'>
96
+
97
+ <link href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" rel="stylesheet">
98
+
99
+ </head>
100
+
101
+
102
+
103
+ <body>
104
+
105
+ <header>
106
+
107
+ <img class="basket" src="http://illustrain.com/img/work/2016/illustrain02-shopping07.png">
108
+
109
+ <p class="title">Shopping basket</p>
110
+
111
+ <p class="sabtitle">商品注文ページ</p>
112
+
113
+ </header>
114
+
115
+
116
+
117
+ <form action="lastconfirm.php" method="post">
118
+
119
+ <div class="product-wrapper">
120
+
121
+ <div class="container">
122
+
123
+ <img class="product-image" src="<?php echo $menu->getImage() ?>">
124
+
125
+ <div class="top-right">
126
+
127
+ <p class="product-name"><?php echo $menu->getName() ?></p>
128
+
129
+ <p class="product-price">¥<?php echo $menu->getPrice() ?> (税込)</p>
130
+
131
+ <div class="top-amount">
132
+
133
+ <span class="font">数量</span>
134
+
135
+ <input class="product-amount" type="text" name="<?php echo $menu->getName() ?>" value="0">
136
+
137
+ <span class="font">個</span>
138
+
139
+ </div>
140
+
141
+ <input class="product-decision" type="submit" value="注文を確定する">
142
+
143
+ </div>
144
+
145
+ </div>
146
+
147
+ <div class="clear"></div>
148
+
149
+ </div>
150
+
151
+ </form>
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+ </body>
160
+
161
+ </html>
162
+
163
+
164
+
165
+ ```
166
+
167
+ ```php
168
+
169
+
170
+
171
+ <!--lastconfirm.php(値を受けて表示するファイル)-->
172
+
173
+
174
+
175
+  <body>
176
+
177
+ <div class="confirm-wrapper">
178
+
179
+ <?php foreach($products as $product) :?>
180
+
181
+ <?php
182
+
183
+ $orderCount = filter_input(INPUT_POST,$product->getName());
184
+
185
+     
186
+
187
+      echo $product->getName();
188
+
189
+ echo $orderCount;
190
+
191
+ echo $product->getPrice();
192
+
193
+
194
+
195
+ ?>
196
+
197
+ <?php endforeach ?>
198
+
199
+
200
+
201
+ </body>
202
+
203
+ ```
204
+
205
+ ```php
206
+
207
+ <!--prodata.php(インスタンスのファイル)-->
208
+
37
209
    
38
210
 
211
+   <?php
212
+
213
+ require_once('promenu.php');
214
+
215
+
216
+
217
+
218
+
219
+ $alfort = new Product('New','画像URL ','アルフォート(20枚入)',307);
220
+
221
+ $calpas = new Product('New','画像URL ','徳用カルパス',377);
222
+
223
+ $lumand = new Product('Sold out','画像URL ','ルマンド(3袋入)',315);
224
+
225
+ $country = new Product('New','画像URL ','カントリーマーム(チョコ&バニラ)',370);
226
+
227
+ $oreo = new Product('A few','画像URL ','OREO 1箱(2袋入)',191);
228
+
229
+ $happy = new Product('New','画像URL ','ハッピーターン(3袋入)',691);
230
+
231
+
232
+
39
- <form action="lastconfirm.php" method="post">
233
+ $products = array($alfort,$calpas,$lumand,$country,$oreo,$happy);
40
-
41
-   <input class="product-amount" type="text" name="<?php echo $menu->getName() ?>" value="0">
234
+
42
-
43
- <!----上のinputでユーザーが注文個数を入力します。>
235
+
44
-
236
+
237
+
238
+
45
- </form>
239
+ ?>
240
+
241
+
46
242
 
47
243
  ```
48
244
 
49
- ```php
50
-
51
-
52
-
53
- <!--lastconfirm.php(値を受けて表示するファイル)-->
54
-
55
-
56
-
57
-  <body>
58
-
59
- <div class="confirm-wrapper">
60
-
61
- <?php foreach($products as $product) :?>
62
-
63
- <?php
64
-
65
- $orderCount = filter_input(INPUT_POST,$product->getName());
66
-
67
-     
68
-
69
-      echo $product->getName();
70
-
71
- echo $orderCount;
72
-
73
- echo $product->getPrice();
74
-
75
-
76
-
77
- ?>
78
-
79
- <?php endforeach ?>
80
-
81
-
82
-
83
- </body>
84
-
85
- ```
86
-
87
- ```php
88
-
89
- <!--prodata.php(インスタンスのファイル)-->
90
-
91
-   
92
-
93
-   <?php
94
-
95
- require_once('promenu.php');
96
-
97
-
98
-
99
-
100
-
101
- $alfort = new Product('New','画像URL ','アルフォート(20枚入)',307);
102
-
103
- $calpas = new Product('New','画像URL ','徳用カルパス',377);
104
-
105
- $lumand = new Product('Sold out','画像URL ','ルマンド(3袋入)',315);
106
-
107
- $country = new Product('New','画像URL ','カントリーマーム(チョコ&バニラ)',370);
108
-
109
- $oreo = new Product('A few','画像URL ','OREO 1箱(2袋入)',191);
110
-
111
- $happy = new Product('New','画像URL ','ハッピーターン(3袋入)',691);
112
-
113
-
114
-
115
- $products = array($alfort,$calpas,$lumand,$country,$oreo,$happy);
116
-
117
-
118
-
119
-
120
-
121
- ?>
122
-
123
-
124
-
125
- ```
126
-
127
245
 
128
246
 
129
247
  ●試したこと

1

「インストラクタ」→「インスタンス」に訂正いたしました。

2019/04/27 05:31

投稿

Tsuyoponpon
Tsuyoponpon

スコア33

test CHANGED
@@ -1 +1 @@
1
- フォームから取得した値をもとに、関連するインストラクタの中身だけを指定して取り出したい。
1
+ フォームから取得した値をもとに、関連するインタンスの中身だけを指定して取り出したい。
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  現在ローカル環境で、商品注文サイトを制作しているのですが、
4
4
 
5
- **「フォームで受け取った値をもとに、インストラクタを指定して中身を取り出す方法」**
5
+ **「フォームで受け取った値をもとに、インスタンスを指定して中身を取り出す方法」**
6
6
 
7
7
  を導き出せず、苦戦しております。
8
8
 
@@ -86,7 +86,7 @@
86
86
 
87
87
  ```php
88
88
 
89
- <!--prodata.php(インストラクタのファイル)-->
89
+ <!--prodata.php(インスタンスのファイル)-->
90
90
 
91
91
    
92
92
 
@@ -132,13 +132,13 @@
132
132
 
133
133
  →エラーになりました。
134
134
 
135
- ②お菓子や、インストラクタを指定するため、「if」での条件分岐を試してみました。
135
+ ②お菓子や、インスタンスを指定するため、「if」での条件分岐を試してみました。
136
136
 
137
137
  →正確なソースがわかりませんでした。
138
138
 
139
139
 
140
140
 
141
- **ユーザーが入力した値(注文数)を情報源に、どのお菓子なのかを見分け、インストラクタの中身を指定してゲッターなどで取り出したいです。(金額や画像)**
141
+ **ユーザーが入力した値(注文数)を情報源に、どのお菓子なのかを見分け、インスタンスの中身を指定してゲッターなどで取り出したいです。(金額や画像)**
142
142
 
143
143
 
144
144