質問編集履歴

2

URLパラメータ追記

2018/09/26 08:23

投稿

pecchan
pecchan

スコア555

test CHANGED
File without changes
test CHANGED
@@ -169,3 +169,9 @@
169
169
  }
170
170
 
171
171
  ```
172
+
173
+
174
+
175
+ URLパラメータは、以下のように渡してます
176
+
177
+ http://localhost/Questions/?question_index=6&answer=消費税は10%になる予定

1

ソースコード追記

2018/09/26 08:23

投稿

pecchan
pecchan

スコア555

test CHANGED
File without changes
test CHANGED
@@ -39,3 +39,133 @@
39
39
  分かる方教えていただけないでしょうか?
40
40
 
41
41
  宜しくお願い致します。
42
+
43
+
44
+
45
+ ------------------------------------------------------------------------
46
+
47
+ 同日追記
48
+
49
+ 失礼しました。ソースコードをまったく記載してなかったので追記します。
50
+
51
+ コントローラで受ける際にエンコードすれば解決出来るのかと思います。
52
+
53
+
54
+
55
+ ビュー側
56
+
57
+ ```ctp
58
+
59
+ <?php echo $this->Form->create('Questions', array('controller'=>'Questions', 'url' => '/Questions/', 'type' => 'GET', 'name' => 'frmExam')); ?>
60
+
61
+
62
+
63
+ <?php foreach ($choices as $ch): ?>
64
+
65
+
66
+
67
+ <p><button type='submit' name='answer' value='<?= h($ch); ?>' class="btn btn-success btn-lg btn-block"><?= h($ch); ?></button></p>
68
+
69
+
70
+
71
+ <?php endforeach; ?>
72
+
73
+
74
+
75
+ <?php if ($question_index != 0 && $question_index + 1 != $question_count){ ?>
76
+
77
+ <p><button type="submit" name="end" value="true" class="btn btn-primary btn-lg btn-block">ここまでで終了して採点する</button></p>
78
+
79
+ <?php } ?>
80
+
81
+ ```
82
+
83
+
84
+
85
+ 表示されるhtml
86
+
87
+ ```html
88
+
89
+ <form action="/kako/Questions/" controller="Questions" name="frmExam" id="QuestionsIndexForm" method="get" accept-charset="utf-8">
90
+
91
+
92
+
93
+ <input type="hidden" name="question_index" value="7">
94
+
95
+
96
+
97
+ <div class="row">
98
+
99
+ <div class="col col-md-12">
100
+
101
+
102
+
103
+
104
+
105
+ <p><button type='submit' name='answer' value='1.いっさい認められていない' class="btn btn-success btn-lg btn-block">1.いっさい認められていない</button></p>
106
+
107
+
108
+
109
+ <p><button type='submit' name='answer' value='2.運用資産全体の10%以内に制限されている' class="btn btn-success btn-lg btn-block">2.運用資産全体の10%以内に制限されている</button></p>
110
+
111
+
112
+
113
+ <p><button type='submit' name='answer' value='3.運用資産全体の20%以内に制限されている' class="btn btn-success btn-lg btn-block">3.運用資産全体の20%以内に制限されている</button></p>
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+ <p><button type="submit" name="end" value="true" class="btn btn-primary btn-lg btn-block">ここまでで終了して採点する</button></p>
124
+
125
+ </div>
126
+
127
+ </div>
128
+
129
+ </form>
130
+
131
+
132
+
133
+ ```
134
+
135
+
136
+
137
+
138
+
139
+ コントローラ側
140
+
141
+ 不具合=パラメータに%などがあった場合に、戻り値が空になったため。
142
+
143
+ パラメータが問題と思い、正誤判定メソッドの中身までは追っていません。
144
+
145
+ ```php
146
+
147
+
148
+
149
+ public function index() {
150
+
151
+
152
+
153
+ $answer = $this->request->query['answer'];
154
+
155
+
156
+
157
+ //一部省略・・・
158
+
159
+
160
+
161
+ //正誤判定を行うメソッド
162
+
163
+ $seigo = score($question, $answer);
164
+
165
+
166
+
167
+
168
+
169
+ }
170
+
171
+ ```