2012-02-03 2 views
5

업로드 프로세스에 uploadify를 사용합니다. 문제는 업로드 할 때마다 리튬이 컨트롤러의보기를 렌더링하려고한다는 것입니다. 필자의 경우에는 uploadify.html.php. 어떻게하면이 동작을 비활성화하고 그냥 200 OK를 반환 할 수 있습니다.리튬에서 렌더링 프로세스 사용 안함

내 컨트롤러 코드 :

class UploadController extends \app\controllers\AppController { 

public function index() {} 

public function uploadify() { 
    Logger::write('info', 'start upload'); 

    if (!empty($this->request->data)) { 
     $fileData = $this->request->data['Filedata']; 
     $error = $fileData['error']; 
     if($error == UPLOAD_ERR_OK) { 
      // everything ok 
      $tempFile = $fileData['tmp_name']; 
      $targetPath = $this->request->env('DOCUMENT_ROOT') . $fileData['folder'] . '/'; 
      $targetFile = str_replace('//','/',$targetPath) . $fileData['name']; 
      move_uploaded_file($tempFile, $targetFile); 
      Logger::write('info', 'upload file successfull to ' . $targetFile); 
     } else if($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) { 
      // file size to large 
      Logger::write('error', 'file to large ' . $fileData['Filename']); 
     } else if($error == UPLOAD_ERR_PARTIAL) { 
      // only partial uplopad 
      Logger::write('error', 'uploaded partial ' . $fileData['Filename']); 
     } else if($error == UPLOAD_ERR_NO_FILE) { 
      // no file uploaded 
      Logger::write('error', 'couldn\'t upload ' . $fileData['Filename']); 
     } else { 
      Logger::write('error', 'Unknown error code ' . $error); 
     } 
    } else { 
     Logger::write('error', 'no form data'); 
    } 
} 
} 

답변

9

는 응답이 아닌 몸의 헤더를 렌더링 redirect()

문서 도구

$this->render(array('head' => true)) 

같은 설정 : 당신은 단지에 행 다음에 추가해야 http://li3.me/docs/lithium/action/Controller::render

+0

은 중요한 것을 반환합니다. -> http://stackoverflow.com/questions/1399654/oncomplete-and-oncompleteall-events-failing-to-fire-when-using-uploadify – Mewel

0

당신은 두 가지 방법으로 이것에 대해 갈 수 있습니다.

첫 번째 방법은 자동 렌더링 해제됩니다 : 약

class MyController extends \lithium\action\Controller { 
    public function __construct(array $config = array()) { 
    $defaults = array('render' => array('negotiate' => true)); 
    return parent::__construct($config + $defaults); 
    } 
} 

당신이 읽을 수있는 더 :

class MyController extends \lithium\action\Controller { 
    public function __construct(array $config = array()) { 
    $defaults = array('render' => array('auto' => false)); 
    return parent::__construct($config + $defaults); 
    } 
} 

을 두 번째 방법은 HTTP Accepts header를 보내 "콘텐츠 유형 협상"을 사용하는 것입니다 컨트롤러 렌더링 방법을 구성하는 방법 here. 에만

+0

thx 전체 수업. 렌더링 프로세스가 필요한 다른 메서드가 있습니다. 방법에 기반한 것이 있다면? 그렇지 않으면 다른 컨트롤러를 만들어야합니다. 업로드를 위해 – Mewel

0

는이 문제를 해결하려면 귀하의 컨트롤러 동작 :

$this->_render['head'] = true;