2013-04-22 3 views
1

$_FILES[..]['error'] 코드를 기반으로 올바른 메시지를 반환하는 사용자 정의 예외를 생성하려고합니다.CodeIgniter가 새로운 사용자 정의 예외를 생성합니다.

class MY_Exceptions extends CI_Exceptions { 
    function My_Exceptions() { 
     parent::CI_Exceptions(); 
    } 

    public function file_upload_error($error_code = UPLOAD_ERR_OK) { 
     switch ($error_code) { 
      case UPLOAD_ERR_INI_SIZE: 
       $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; 
       break; 
      case UPLOAD_ERR_FORM_SIZE: 
       $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; 
       break; 
      case UPLOAD_ERR_PARTIAL: 
       $message = "The uploaded file was only partially uploaded"; 
       break; 
      case UPLOAD_ERR_NO_FILE: 
       $message = "No file was uploaded"; 
       break; 
      case UPLOAD_ERR_NO_TMP_DIR: 
       $message = "Missing a temporary folder"; 
       break; 
      case UPLOAD_ERR_CANT_WRITE: 
       $message = "Failed to write file to disk"; 
       break; 
      case UPLOAD_ERR_EXTENSION: 
       $message = "File upload stopped by extension"; 
       break; 

      default: 
       $message = "Unknown upload error"; 
       break; 
     } 

     log_message('error', $error_code); 
     return $message; 
    }  
} 

하지만 file_upload_error(1)를 호출 할 때 그것은 Call to undefined function file_upload_error()

가 어떻게이 문제를 접근 할 말합니다 :

나는 CI_Exceptions class을 확장했다?

+1

함수가 클래스 외부에 정의되어 있습니까? –

+1

이 클래스 메소드를 어디에 어떻게 호출하는지 알려주십시오. – karmafunk

답변

2

라이브러리 클래스를 올바르게 사용하고 있지 않다는 느낌이 들지만 질문에서 알기 어렵습니다. 모델 또는 컨트롤러 클래스에서, 다음을 사용 :

$this->load->library('exceptions'); 
$message = $this->exceptions->file_upload_error($error_code); 

당신은 예외 라이브러리를로드하도록 지시 할 때, 자동으로 MY_ 접두사와 응용 프로그램/라이브러리/디렉토리에 하나가 있는지 보인다. 그것이 있으면로드 할 것입니다. 그런 다음 다른 라이브러리와 마찬가지로 액세스합니다.

희망이 있습니다.

관련 문제