这是我的控制器代码:
$this->viewClass = 'Media';
$params = array(
'id' => $filename '.gif',
'name' => $filename ,
'download' => false,
'extension' => 'gif',
'path' => $folderpath,
'cache' => '+30 days',
'modified' => '@' . filemtime($pathtofile),
);
$this->set($params);
和回复:
firebug screenshot http://i39.tinypic.com/es56di.png
在core.php中禁用了调试。但是,浏览器(Firefox,Chrome)从不缓存文件并始终下载整个文件。这是因为 200 OK 响应?我该如何解决?
修改 我可能应该添加实际请求URL的示例
http://localhost/mycontroller/mymediaaction/2345
我通过将名称属性设置为action参数而不是实际文件名来解决此问题。我仍然对这种行为的一些解释表示赞赏。
答案 0 :(得分:0)
以下控制器操作的代码段将提供 304 响应或文件。我认为checkNotModified
功能应由内部MediaView::render
功能完成,类似于AssetDispatcher
。但目前这个片段可能会有所帮助。
$modified = @filemtime(ROOT . $dir . $filename);
$this->response->modified($modified);
if ($this->response->checkNotModified($this->request))
{
$this->autoRender = false;
$this->response->send();
}
else
{
$this->viewClass = 'Media';
$params = array('id' => $filename,
'cache' => '+1 day',
'modified' => '@' . $modified, // Must be a string to work. See MediaView->render()
'path' => ROOT . $dir);
$this->set($params);
}
return;