2014-10-16 3 views
1

하나의 함수가 call_back 함수 인 곳에서 함수를 사용해야합니다. 이제 나는 "$ iamge_location"변수의 값을 다른 함수로 가져오고 싶다. 콜백 함수에서 값을 반환하고 콜백 함수가 호출 된 다른 함수로 인쇄하려고합니다. 컨트롤러에서한 기능에서 다른 기능으로 가치를 얻는 방법?

function RoomImageAdd(){ 
     $this->form_validation->set_rules('roomImage', 'Upload Image', 'callback_upload_Image'); 

     $roomid = $this->input->post('roomid'); 

     if ($this->form_validation->run() == FALSE) { 
      $this->addRoomImage($roomid); 
     } 
     else { 
      echo $image_location; 
     } 
    } 

    function upload_Image(){ 

     if(!empty($_FILES['roomImage']['name'])) 
     { 
      $filename = date('YmdHis'); 

      $config['upload_path'] = 'assets/img/upload/rooms/'; 
      $config['allowed_types'] = 'jpg|jpeg'; 
      $config['file_name'] = $filename; 
      $config['max_size'] = '2000'; 
      $config['remove_spaces'] = true; 
      $config['overwrite'] = false; 

      $this->upload->initialize($config); 

      if (!$this->upload->do_upload('roomImage')) 
      { 
       $this->form_validation->set_message('upload_Image', $this->upload->display_errors('','')); 
       return FALSE; 
      } 
      else 
      { 
       $image_data = $this->upload->data(); 

       $image_location = 'assets/img/upload/rooms/'.$image_data['file_name']; 

       $config['image_library'] = 'gd2'; 
       $config['source_image'] = $image_data['full_path']; 
       $config['new_image'] = $image_data['file_path'].'room_thumb/'; 
       $config['maintain_ratio'] = FALSE; 
       $config['create_thumb'] = TRUE; 
       $config['thumb_marker'] = '_thumb'; 
       $config['width'] = 280; 
       $config['height'] = 280; 

       $this->image_lib->initialize($config); 

       if (!$this->image_lib->resize()) { 

        $error = array('error' => $this->image_lib->display_errors()); 

       } else { 

        $this->image_lib->resize(); 
       } 
       return $image_location; 
      } 
     } 
     else{ 
      $this->form_validation->set_message('upload_Image', "Unexpected Error! No File Selected!"); 
      return FALSE; 
     } 
    }  
+0

변수를 전역으로 설정하여 사용하십시오. – shafiq

답변

1

당신이 당신의 update_Image 기능에서 설정할 수 image_location 변수 필드를 추가 할 수 있어야한다 :하지만 난

여기 내 컨트롤러 코드입니다 .. 값 PLZ의 도움을받을하지 않았다.

변경

return $image_location; 

$this->image_location = $image_location; 
return true; // because a boolean is expected off of a validation callback 

에 지금 당신은 당신의 RoomImageAdd 방법에 위치에 액세스 할 수 $this->image_location를 사용할 수 있습니다.

+0

위대한 그것은 완벽하게 작동합니다. 고맙습니다. –

관련 문제