2014-02-25 3 views
0

원하는 변수 만 함수로 보낼 수 있습니까? 난에 거짓 $ ENC =를 설정할 예컨대 이런 기능특정 변수를 함수에 전송

function upload_file($field = "thumbnail",$types = 'gif|jpg|jpeg|png|pdf',$folder = "",$size = '0',$w = '0',$h = '0', $enc = false) 
    { 
     if ($folder == "") 
     { 
      $config['upload_path'] = './Media/uploads/'; 
     } 
     else 
     { 
      if (!is_dir("./Media/uploads/$folder/")) 
      { 
        mkdir("./Media/uploads/$folder/"); 
      } 
      $config['upload_path'] = "./Media/uploads/$folder/"; 
     } 
     $config['allowed_types'] = $types; 
     $config['max_size'] = $size; 
     $config['max_width'] = $w; 
     $config['max_height'] = $h; 
     $config['encrypt_name'] = $enc; 

     $this->load->library('upload', $config); 

     if (! $this->upload->do_upload($field)) 
     { 
      $error = array('error' => $this->upload->display_errors()); 
      print_r($error); 

      return array(false,$error); 
     } 
     else 
     { 
      $data = array('upload_data' => $this->upload->data()); 

      return array(true,$data); 
     } 
    } 

가 나는

function upload_file($field = "thumbnail",$types = 'gif|jpg|jpeg|png|pdf',$folder = "",$size = '0',$w = '0',$h = '0', $enc = false) 

에 포함 된 설정 변수에서이

처럼 사용할 이

$data = $this->base_model->upload_file(); 

를 사용하여 $ ENC = 사실이 일어날 수 있도록하는 방법은 무엇입니까?

+1

'$ enc = true'를 함수 프로파일에 넣지 않는 이유는 무엇입니까? 그런 식으로'$ this-> base_model-> upload_file();이 당신이 원하는 것을 제공 할 것입니다 ... – anthonygore

답변

0

왜 함수 프로파일에 $enc = true을 설정하지 않으셨습니까? 기본 $enc = true 당신이 목표로하고하지 무엇 때문에 그런 식으로 $this->base_model->upload_file(); 단지 함수 서명을 변경하는 경우 $enc = true

$data = $this->base_model->upload_file("thumbnail",'gif|jpg|jpeg|png|pdf',"",'0','0','0',true);

+0

이 작동하지만 너무 길면 입력 할 수 없습니다. 어쩌면 어떤 종류의 지름길이 $ enc가 유일한 것일 것입니다. – itsover9000

+0

@ itsover9000이 유일한 옵션입니다. 그렇지 않으면 다른 값을 'NULL'로 넣습니다. –

0

와 매개 변수를 다시

하거나 간단한 설정을 원하는 것을 제공 할 것입니다 (보통은 기본값이 false으로 유지되기를 원하지만) 호출에서 함수 정의의 다른 기본값을 다시 반복하여 겹쳐 쓰고 싶지는 않습니다 (개발할 때마다 정의가 바뀌는 경우를 대비하여) 다음 매개 변수에 대해 null 값을 전달하십시오 :

$data = $this->base_model->upload_file(null, null, null, null, null, null, true); 

null 매개 변수는 실제로 "전달되지"않으므로 함수는 서명에 정의 된대로 기본값을 사용합니다. 마지막 매개 변수는 true$enc 변수에 전달되므로 기본값이 아닙니다.