안녕하세요 모두 cakephp의 데이터베이스 테이블을 업데이트하는 데 문제가 있습니다 ... 로그인 한 사용자가 자신의 개인 정보를보고 업데이트 할 수있는 프로필 페이지가 있습니다. 여기 내 솔루션 (그래 난 ... 그것은 최고의하지 알고) cakephp가
if($this->request->is('post')) {
$data = $this->request->data['user-profile'];
// $uid = $this->Session->read("WebUser.id");
$uid = 1;
$user_data = $this->WebUser->find('first', array('conditions'=>array('id'=>$uid)));
$updated_fields = '';
foreach($data as $key => $value) {
if($key != 'state'){
if(empty($value)) {
$this->Session->setFlash("Please fill in all the required fields");
return;
}
}
if($user_data['WebUser'][$key] != $value) {
if($key == 'email') {
$mail_check = $this->WebUser->find('first', array('conditions'=>array('email'=>$value, 'id !='=>$uid)));
if($mail_check) {
$this->Session->setFlash("This e-mail is already registered");
return;
}
}
$updated_fields .= "'".$key."'=>'".$value."',";
}
}
if($updated_fields != '') {
$updated_fields .= "'modified'=>'".date("Y-m-d H:i:s")."'";
$this->WebUser->read(null, $uid);
$this->WebUser->set(array('first_name'=>'John','modified'=>'2014-12-30 10:53:00'));
if($this->WebUser->save()) {
$this->printr($this->data);
$this->WebUser->save();
$this->Session->setFlash("Success : Profile data is now modified", array("class"=>"success_msg"));
} else {
$this->Session->setFlash("Error : Data modifying isn't complete. Please try agin!");
}
}
return;
}
그래서이 코드는 데이터베이스에서 사용자 정보를 가져오고 해당 필드 마녀를 찾는 것은 프로필 페이지에 편집이다. 문제는 내가 다시 허위로주고 저장하지 않은 데이터를 저장하려고 할 때입니다. Some1은 이것을위한 해결책이 있습니까? 나는 아직 찾지 못했다. (추신 : 나는 cakePHP : D로 새것임)
사용자가이 양식을 제출할 때 오류 메시지가 인쇄됩니까? 또한보기 코드를 첨부 해주십시오. 나는 edit.ctp 또는 뭔가라고 생각한다. – bcesars