简体   繁体   English

禁用锂中的渲染过程

[英]Disable render process in lithium

i use uploadify for my upload process. 我使用uploadify进行上传过程。 The problem is that after each upload lithium tries to render the view of the controller. 问题是每次上传后锂都会尝试渲染控制器的视图。 In my case uploadify.html.php. 在我的情况下uploadify.html.php。 How can i disable this behaviour and just return a 200 OK. 如何禁用此行为并返回200 OK。

My controller code: 我的控制器代码:

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

To only renders the headers of the response, not the body, set 仅渲染响应的标题,而不是正文

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

Same with redirect() redirect()相同

Docs: http://li3.me/docs/lithium/action/Controller::render 文件: http//li3.me/docs/lithium/action/Controller :: render

要解决此问题,您只需在控制器操作中添加以下行:

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

You can go about this in one of two ways. 你可以用两种方式之一来解决这个问题。

The first approach is turning off 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);
  }
}

The second approach would be to use "content-type negotiation" by sending a HTTP Accepts header : 第二种方法是通过发送HTTP Accepts标头来使用“内容类型协商”:

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

You can read more about how to configure how the controller renders here . 您可以阅读有关如何配置控制器在此处呈现的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM