2016-06-29 1 views
0

에 따라, 나는 아래처럼 내 필드의 유효성을 검사 :Phalcon의 유효성 필드는이 모델의 <code>validate()</code> 기능에, 내가 컬렉션 모델을 가지고, 내가 Phalcon 프레임 워크를 사용하여 다른 필드

class Users extends Collection 
{ 


    public function validation() 
    { 

     $this->validate(
      new EmailValidator(
       array(
        "field" => "email", 
        "message" => "email is not valid" 
       ) 
      ) 
     ); 

     $this->validate(
      new NumericalityValidator(
       array(
        "field" => "phone", 
        "message" => "phone is not valid" 
       ) 
      ) 
     ); 


     return $this->validationHasFailed() != true; 
    } 

} 

어떻게 내가이 모델 하나에 전화 이 두 필드 중 필수 항목은 무엇입니까? 예를 들어 tel가 비어 있지 않거나 전자 메일이 비어 있거나 전자 메일이 비어 있지 않은 경우 tel가 비어있을 수 있으며 두 필드가 모두 비어 있으면 유효성 검사가 실패해야합니다.

답변

0

이와 비슷한?

public function validation() 
{ 
    if(empty($this->phone)) { 
     $this->validate(
      new EmailValidator(
       array(
        "field" => "email", 
        "message" => "email is not valid" 
       ) 
      ) 
     ); 
    } 

    if(empty($this->email)) { 
     $this->validate(
      new NumericalityValidator(
       array(
        "field" => "phone", 
        "message" => "phone is not valid" 
       ) 
      ) 
     ); 
    } 


    return $this->validationHasFailed() != true; 
} 
+0

감사합니다. 그러나 제 뜻은 아닙니다. – Ali

0

메시지를 추가 할 수 있어야합니다. https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Message.html

<?php 

use Phalcon\Mvc\Model\Message as Message; 

public function validation() 
{ 
    if(empty($this->phone) && empty($this->email)) { 
     $message = new Message('Phone or email must be provided', 
           array('phone','email'), 
           'PresenceOf'); 
    $this->appendMessage($message); 
    return $this->validationHasFailed() != true; 
}