2012-10-25 3 views
0

을 저장 얻을 사용자 (자신의 이메일 또는 사용자 이름)이 존재하는 경우 검색하기 전에, 그것은이 내 공개 부가 기능이지만, 약간의 실수가 CakePHP의에게

,이 기능은 어쨌든을 절약 할 수 있음 !

그래서 [사용자] [전자 메일]로 검색 한 다음 [사용자] [사용자 이름]으로 검색하여 데이터베이스로 이동할 사용자 이름과 전자 메일이 사용자 이름이 새 데이터임을 확인하는 방법은 무엇입니까? 이메일

public function add() { 
    if ($this->request->is('post')) { 
     ////here it should be the query ! 
     $this->User->create(); 
     if ($this->User->save($this->request->data)) { 
    $this->redirect(array('controller' => 'users', 'action' => 'login')); 
      $this->redirect(array('action' => 'index')); 
     } else { 
      $this->Session->setFlash(__('الموقع مش عارف يسيفك يا فقيع, حاول تاني')); 
     } 
    } 
} 
+0

가 내장 된 [isUnique에 (http://book.cakephp.org/1.3/view/1166/isUnique) 유효성 검사 규칙을 사용하여 사용자 모델에서 유효성 검사를 추가 . – Ross

답변

1

public $validate = array(
    'username' => array(
     'emailEmpty' => array(
      'rule' => 'notEmpty', 
      'message' => 'Sorry, email cannot be empty', 
      'last' => true, 
     ), 
     'email' => array(
      'rule' => array('email'), 
      'message' => 'Must be a valid email', 
      'last' => true, 
     ), 
     'emailExists' => array(
      'rule' => 'isUnique', 
      'message' => 'Sorry, this email address is already in use', 
     ), 
    ), 

); 
+0

주문 및 누락 된 "last"=> true를 제외하고 – mark

+0

덕분에 도움이되었습니다. –

+0

@mark, 당신은 무엇을 의미합니까? –

관련 문제