URL から Cakephp コントローラーにパラメーターを送信する必要があります。'ufrom' と 'uto' の 2 つのパラメーターを持つメッセージ テーブルがあります。コントローラーでは、この値をメッセージテーブルに保存したいと考えています。
URLを入れました:
http://localhost/ar/messages/add?ufrom=9&uto=3
MessagesController には機能があります:
public function add() {
if(($this->request->query['uto'])and($this->request->query['ufrom'])){
$this->Message->create();
if ($this->Message->save($this->request->data)) {
$this->set('addMessage',TRUE);
$this->set('ufrom',$this->request->query['ufrom']);
$this->set('uto',$this->request->query['uto']);
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The message could not be saved. Please, try again.'));
}
$targets = $this->Message->Target->find('list');
$this->set(compact('targets'));
}
else{
$this->set('error',true);
}
}
そしてadd.ctpには次のものがあります:
<?php
if(isset($error)){
echo('error');
}
else{
echo json_encode($ufrom);
echo json_encode($uto);
echo json_encode($addMessage);
}
?>
しかし、上記の URL を使用すると、次のように表示されます。
Notice (8): Undefined variable: ufrom [APP\View\Messages\add.ctp, line 6]null
Notice (8): Undefined variable: uto [APP\View\Messages\add.ctp, line 7]null
Notice (8): Undefined variable: addMessage [APP\View\Messages\add.ctp, line 8]null
データベースには何も保存されません。私はcakephpが初めてです。助けてください。