質問編集履歴

5

解決のため

2016/04/16 23:35

投稿

sota_u
sota_u

スコア88

test CHANGED
File without changes
test CHANGED
@@ -262,6 +262,88 @@
262
262
 
263
263
  ```
264
264
 
265
+
266
+
267
+ 【2016/04/17 8:33 追加】
268
+
269
+ ・$dataをassignの指定先を修正
270
+
271
+ ●sample.php
272
+
273
+ ```
274
+
275
+ <?php
276
+
277
+ if ( ! defined('BASEPATH')) exit('No direct script access allowed');
278
+
279
+
280
+
281
+ require_once(dirname(__FILE__).'/MY_Controller.php');
282
+
283
+
284
+
285
+ class Sample extends MY_Controller {
286
+
287
+ public $user_data;
288
+
289
+ public function __construct()
290
+
291
+ {
292
+
293
+ parent::__construct();
294
+
295
+ }
296
+
297
+
298
+
299
+ // 設定画面
300
+
301
+ public function index()
302
+
303
+ {
304
+
305
+ // ユーザーデータを取得
306
+
307
+ $user_data_query = $this->db->query('SELECT * FROM tbl_m_user');
308
+
309
+ $data = array();
310
+
311
+
312
+
313
+ foreach ($user_data_query->result() as $row)
314
+
315
+ {
316
+
317
+ $data[$row->user_id] = $row->user_name;
318
+
319
+ }
320
+
321
+ print_r($data);
322
+
323
+ $this->smarty->assign('user_data', $data);
324
+
325
+ $this->smarty->display('index.tpl');
326
+
327
+ }
328
+
329
+
330
+
331
+ // 結果画面
332
+
333
+ public function result()
334
+
335
+ {
336
+
337
+ $this->view('result.tpl');
338
+
339
+ }
340
+
341
+ }
342
+
343
+ ?>
344
+
345
+ ```
346
+
265
347
  ###補足情報(言語/FW/ツール等のバージョンなど)
266
348
 
267
349
  ![イメージ説明](b35b2ff6cce2e15b67461ef72ed3f9b5.png)

4

アドバイスを元に修正

2016/04/16 23:35

投稿

sota_u
sota_u

スコア88

test CHANGED
File without changes
test CHANGED
@@ -170,9 +170,97 @@
170
170
 
171
171
  ###試したこと
172
172
 
173
+ 【2016/04/10 12:52 追加】
174
+
175
+ ・配列「$data」の形を修正
176
+
177
+ ・変数「user_data」に格納する値の記述方法を修正
178
+
179
+ ●sample.php
180
+
181
+ ```
182
+
183
+ <?php
184
+
185
+ if ( ! defined('BASEPATH')) exit('No direct script access allowed');
186
+
187
+
188
+
189
+ require_once(dirname(__FILE__).'/MY_Controller.php');
190
+
191
+
192
+
193
+ class Sample extends MY_Controller {
194
+
195
+ public function __construct()
196
+
197
+ {
198
+
199
+ parent::__construct();
200
+
201
+ }
202
+
203
+
204
+
205
+ // 設定画面
206
+
207
+ public function index()
208
+
209
+ {
210
+
211
+ $tpl = 'index';
212
+
213
+
214
+
215
+ // ユーザーデータを取得
216
+
217
+ $user_data_query = $this->db->query('SELECT * FROM tbl_m_user');
218
+
219
+ $data = array();
220
+
221
+
222
+
223
+ foreach ($user_data_query->result() as $row)
224
+
225
+ {
226
+
227
+ // 配列の形を修正
228
+
229
+ $data[$row->user_id] = $row->user_name;
230
+
231
+ }
232
+
233
+ $smarty = new Smarty();
234
+
173
- 課題に対してアプローチしたこと記載してください
235
+ // 格納する値の指定修正
236
+
174
-
237
+ $smarty->assign('user_data', $data);
238
+
175
-
239
+ print_r($user_data);
240
+
241
+ $this->view($tpl . '.tpl', $user_data);
242
+
243
+ }
244
+
245
+
246
+
247
+ // 結果画面
248
+
249
+ public function result()
250
+
251
+ {
252
+
253
+ $tpl = 'result';
254
+
255
+ $this->view($tpl . '.tpl');
256
+
257
+ }
258
+
259
+ }
260
+
261
+ ?>
262
+
263
+ ```
176
264
 
177
265
  ###補足情報(言語/FW/ツール等のバージョンなど)
178
266
 

3

表記方法を修正

2016/04/10 03:59

投稿

sota_u
sota_u

スコア88

test CHANGED
File without changes
test CHANGED
@@ -42,9 +42,13 @@
42
42
 
43
43
 
44
44
 
45
+
46
+
45
47
  ●sample.php(コントローラー)
46
48
 
49
+ ```
50
+
47
- ```<?php
51
+ <?php
48
52
 
49
53
  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
50
54
 
@@ -120,9 +124,11 @@
120
124
 
121
125
  ?>
122
126
 
123
-
127
+ ```
124
128
 
125
129
  ●index.tpl
130
+
131
+ ```
126
132
 
127
133
  <!DOCTYPE html>
128
134
 
@@ -160,7 +166,9 @@
160
166
 
161
167
  </html>
162
168
 
169
+ ```
170
+
163
- ```###試したこと
171
+ ###試したこと
164
172
 
165
173
  課題に対してアプローチしたことを記載してください
166
174
 

2

コードを見やすく変更する。

2016/04/09 16:38

投稿

sota_u
sota_u

スコア88

test CHANGED
File without changes
test CHANGED
@@ -40,15 +40,11 @@
40
40
 
41
41
  ###該当のソースコード
42
42
 
43
- ```ここに言語を入力
44
43
 
45
- ここにご自身が実行したソースコードを書いてください
46
-
47
- ```
48
44
 
49
45
  ●sample.php(コントローラー)
50
46
 
51
- <?php
47
+ ```<?php
52
48
 
53
49
  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
54
50
 
@@ -164,7 +160,7 @@
164
160
 
165
161
  </html>
166
162
 
167
- ###試したこと
163
+ ```###試したこと
168
164
 
169
165
  課題に対してアプローチしたことを記載してください
170
166
 

1

ソースの添付間違い

2016/04/09 16:35

投稿

sota_u
sota_u

スコア88

test CHANGED
File without changes
test CHANGED
@@ -27,6 +27,14 @@
27
27
  正しい記述方法をご存知の方、ご教授いただけないでしょうか・・・?
28
28
 
29
29
  よろしくお願い致します。
30
+
31
+
32
+
33
+ 2016/04/10 1:11 追記
34
+
35
+ 申し訳ありません、一部ソースの添付間違いがあったため修正しました。
36
+
37
+ 改めてお願い致します。
30
38
 
31
39
 
32
40
 
@@ -74,7 +82,7 @@
74
82
 
75
83
  // ユーザーデータを取得
76
84
 
77
- $user_data_query = $this->db->query('SELECT * FROM tbl_m_user');
85
+ $data['user_data'][] = array('user_id' => $row->user_id, 'user_name' => $row->user_name);
78
86
 
79
87
  $data = array();
80
88
 
@@ -84,73 +92,13 @@
84
92
 
85
93
  {
86
94
 
87
- $data['user_data'][] = array('user_id' => $row->user_id, 'user_name' => $row->user_name);
95
+ $data[] = array($row->user_id => $row->user_name);
88
96
 
89
97
  }
90
98
 
91
- print_r($data);
99
+ $smarty = new Smarty();
92
100
 
93
- $this->view($tpl . '.tpl', $data);
101
+ $smarty->assign('user_data', 'data');
94
-
95
- }
96
-
97
-
98
-
99
- }
100
-
101
- ?>
102
-
103
-
104
-
105
- ●index.tpl
106
-
107
- <?php
108
-
109
- if ( ! defined('BASEPATH')) exit('No direct script access allowed');
110
-
111
-
112
-
113
- require_once(dirname(__FILE__).'/MY_Controller.php');
114
-
115
-
116
-
117
- class Sample extends MY_Controller {
118
-
119
- public function __construct()
120
-
121
- {
122
-
123
- parent::__construct();
124
-
125
- }
126
-
127
-
128
-
129
- // 設定画面
130
-
131
- public function index()
132
-
133
- {
134
-
135
- $tpl = 'index';
136
-
137
-
138
-
139
- // ユーザーデータを取得
140
-
141
- $user_data_query = $this->db->query('SELECT * FROM tbl_m_user');
142
-
143
- $data = array();
144
-
145
-
146
-
147
- foreach ($user_data_query->result() as $row)
148
-
149
- {
150
-
151
- $data['user_data'][] = array('user_id' => $row->user_id, 'user_name' => $row->user_name);
152
-
153
- }
154
102
 
155
103
  print_r($data);
156
104
 
@@ -178,12 +126,52 @@
178
126
 
179
127
 
180
128
 
129
+ ●index.tpl
130
+
131
+ <!DOCTYPE html>
132
+
133
+ <html lang="ja">
134
+
135
+ <head>
136
+
137
+ <meta charset="UTF-8">
138
+
139
+ <title>Document</title>
140
+
141
+ </head>
142
+
143
+ <body>
144
+
145
+ <form method="post" action="/sample/result">
146
+
147
+ <label for="user_select">ユーザー情報</label>
148
+
149
+ <select id="user_select">
150
+
151
+ {foreach from=$user_data key=user_id item=user_name}
152
+
153
+ <option value="{$user_id}">{$user_name}</option>
154
+
155
+ {/foreach}
156
+
157
+ </select><br>
158
+
159
+ <input type="submit" value="確認">
160
+
161
+ </form>
162
+
163
+ </body>
164
+
165
+ </html>
166
+
181
167
  ###試したこと
182
168
 
183
169
  課題に対してアプローチしたことを記載してください
184
170
 
185
171
 
186
172
 
187
- ###補足情報(言語/FW/ツール等のバージョンなど)![![イメージ説明](29280f76238029c871d28bbb86d795fc.png)](54494ea51d92c4942af984122e2a0562.png)
173
+ ###補足情報(言語/FW/ツール等のバージョンなど)
174
+
175
+ ![イメージ説明](b35b2ff6cce2e15b67461ef72ed3f9b5.png)
188
176
 
189
177
  より詳細な情報