2011-09-01 8 views
2

symfony 1.4 doctrine을 사용하고 있습니다. 전화 번호의 유효성을 검사 할 수있는 코드는 다음과 같습니다. (이 웹 사이트 "http://jasonswett.net/blog/how-to-validate-and-sanitize-a-phone-number-in-symfony/")사용자 정의 폰 검사기가 작동하지 않습니다. symfony

lib 폴더에 붙여 넣었습니다.

apps/frontend/lib/myValidatorPhone.class.php 
<?php 

/** 
* myValidatorPhone validates a phone number. 
* 
* @author Jason Swett (http://jasonswett.net/how-to-validate-and-sanitize-a-phone-number-in-symfony/) 
*/ 
class myValidatorPhone extends sfValidatorBase 
{ 
    protected function doClean($value) 
    { 
    $clean = (string) $value; 

    $phone_number_pattern = '/^(\((\d{3})\)|(\d{3}))\s*[-\.]?\s*(\d{3})\s*[-\.]?\s*(\d{4})$/'; 

    if (!$clean && $this->options['required']) 
    { 
     throw new sfValidatorError($this, 'required'); 
    } 

    // If the value isn't a phone number, throw an error. 
    if (!preg_match($phone_number_pattern, $clean)) 
    { 
     throw new sfValidatorError($this, 'invalid', array('value' => $value)); 
    } 

    // Take out anything that's not a number. 
    $clean = preg_replace('/[^0-9]/', '', $clean); 

    // Split the phone number into its three parts. 
    $first_part = substr($clean, 0, 3); 
    $second_part = substr($clean, 3, 3); 
    $third_part = substr($clean, 6, 4); 

    // Format the phone number. 
    $clean = '('.$first_part.') '.$second_part.'-'.$third_part; 

    return $clean; 
    } 
} 

는 그럼 난 내 양식 폴더

lib/form/doctrine/reservation/reservationApplicationForm.class.php 
$this->validatorSchema['telephone'] = new myValidatorPhone(array(
     'required' => false, 
    )); 

에이 코드를 생성하지만이 프로그램을 실행할 때 오류를 얻을 :이 코드는 1.4에서 작동 웹 사이트를 기반으로

Fatal error: Class 'myValidatorPhone' not found in C:\www\project\reservation\lib\form\doctrine\reservationApplicationForm.class.php on line 36

나는 그것을 지금 사용하고있다. 그러나 나는 왜 나는 치명적인 오류가 있는지 모르겠다. 당신의 lib 폴더에

답변

5

폴더 검사기를 만들고 lib에 그것으로 당신의 검증을 넣어/검증/myValidatorPhone.class.php

+0

감사합니다! 효과가있다. – Martin

관련 문제