URL에서 cakephp 컨트롤러로 매개 변수를 전송해야합니다. 메시지 테이블에 두 개의 매개 변수 'ufrom'과 'uto'가 있습니다. 컨트롤러에서이 값을 메시지 테이블에 저장하려고합니다.URL에서 cakephp로 매개 변수를 전달하십시오.
가 나는 URL에 넣어 :
MessagesController에서http://localhost/ar/messages/add?ufrom=9&uto=3
내가 가진 기능 :
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에서 새로운 사람입니다. 도와주세요. 여기
내 데이터는 아직 데이터베이스에 저장되지 않습니다. – sahar
http://stackoverflow.com/questions/9394080/cakephp-2-0-cannot-save pls this를 참조하십시오. – liyakat
감사합니다. 내 문제가 해결되었습니다. – sahar