php - SS_HTTPRequest could not be converted to a string -
i have silverstripe (3.4) page form work if didn't have dataobject
in it.
public function antwortform($id) { $nummer = vortest_fragen::get()->byid($id); if ($nummer) { $art=$nummer->art; } if ($art == 'normal') { $fields = new fieldlist( textareafield::create('antwort'), hiddenfield::create('id', 'id', $id), hiddenfield::create('vortestid', 'vortestid', $this->request->param('id')), hiddenfield::create('aktion', 'aktion', $this->request->param('action')) ); } else { $optionen = explode(';', $nummer->optionen); $a = 'a'; ( $i = 0 ; $i < count ($optionen); $i++) { $op[$a] ='<div style="width:25px;display:inline;">' . $a . ')</div> ' . $optionen[$i]; $a++; } $fields = new fieldlist( checkboxsetfield::create('antwort', 'antwort', $op), hiddenfield::create('id', 'id', $id), hiddenfield::create('vortestid', 'vortestid', $this->request->param('id')), hiddenfield::create('aktion', 'aktion',$this->request->param('action')), hiddenfield::create('art', 'art', $nummer->art) ); } $actions = new fieldlist( formaction::create('antworteintragen', 'eintragen') ); $form = new form($this, 'antwortform', $fields, $actions); return $form; } function antworteintragen($data, $form) { $antwort = vortest_antwort::get()->filter(array('frageid' => $data['id'], 'schreiberid' => member::currentuserid())); foreach($antwort $item) { $item->delete(); } foreach ($data['antwort'] $antwort) { $ant .= $antwort . ','; } $antwort = new vortest_antwort(); if ($data['antwort']) { $form->saveinto($antwort); if ($data['art'] == 'mechanics') { $antwort->antwort = $ant; } $antwort->schreiberid = member::currentuserid(); $antwort->frageid = $data['id']; $antwort->write(); } $vid = $data['vortestid']; if ($data['aktion'] == 'allefragen') { $this->redirect('/vortest/allefragen/' . $vid . '#' . $data['fragenr']); } elseif ($data['aktion'] == 'einzelfrage') { $this->redirect('/vortest/einzelfrage/' . $vid); } else { $this->redirect('/vortest/test/' . $vid.'#' . $data['fragenr']); } }
it works when change $id
number in line $nummer = vortest_fragen::get()->byid($id);
when don't change following error:
[recoverable error] object of class ss_httprequest not converted string
how fix problem?
althought not documented, silverstripe secretly passes request argument , form methods on controller. $id argument not think is, find ss_httprequest object silverstripe has passed (without realising).
to fix this, change first line:
public function antwortform($id) {
to:
public function antwortform($request, $id) {
and make sure update anywhere call method :-)
Comments
Post a Comment