2012-02-03 27 views
5

tôi sử dụng uploadify cho quá trình tải lên của tôi. Vấn đề là sau mỗi lần tải lên, lithium cố gắng hiển thị chế độ xem của bộ điều khiển. Trong trường hợp của tôi uploadify.html.php. Làm thế nào tôi có thể vô hiệu hóa hành vi này và chỉ trả lại 200 OK.Vô hiệu hóa quá trình hiển thị trong lithium

mã điều khiển của tôi:

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'); 
    } 
} 
} 

Trả lời

9

Để chỉ làm cho các tiêu đề của câu trả lời, không phải là cơ thể, thiết

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

Cùng với redirect()

Documents: http://li3.me/docs/lithium/action/Controller::render

+0

để tải lên điều quan trọng của nó để trả lại thứ gì đó -> http://stackoverflow.com/questions/1399654/oncomplete-and-oncompleteall-events-failing-to-fire-when-using-uploadify – Mewel

0

Bạn có thể đi về vấn đề này theo một trong hai cách.

Phương pháp đầu tiên là tắt auto rendering:

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

Cách tiếp cận thứ hai sẽ được sử dụng "đàm phán content-type" bằng cách gửi một HTTP Accepts header:

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

Bạn có thể đọc thêm về cách cấu hình cách bộ điều khiển hiển thị here.

+0

thx, nhưng chỉ hoạt động cho cả lớp. tôi có các phương pháp khác cần quá trình render. nếu có phương pháp nào đó dựa trên? Nếu không, tôi phải tạo một Controller khác. – Mewel

0

Để khắc phục điều này, bạn chỉ cần thêm sau dòng để hành động điều khiển của bạn:

$this->_render['head'] = true; 
Các vấn đề liên quan