單擊CMS中的按鈕下載PDF文件時出現問題。我正在使用模塊BetterButtons。按鈕本身工作正常,但下載文件時出現錯誤。我總是得到這個錯誤:Silverstripe 3.2:如何使用按鈕強制從CMS下載文件?
Failed to load resource: the server responded with a status of 500 (Warning at line 257 of /Applications/MAMP/htdocs/myproject/framework/control/HTTPResponse.php)
和
[Recoverable Error] Object of class SS_HTTPResponse could not be converted to string.
所以我假定行
return SS_HTTPRequest::send_file($filedata, $fileName, 'application/pdf');
錯誤或東西是錯誤的$ FILEDATA ...什麼是正確的方式要做到這一點?
我的代碼:
在我的數據對象,我有下載按鈕:
private static $better_buttons_actions = array (
'printFilesPDF'
);
public function getBetterButtonsActions() {
$fields = parent::getBetterButtonsActions();
$fields->push(BetterButtonCustomAction::create('printFilesPDF', 'Print files'));
return $fields;
}
public function printFilesPDF() {
$filedata = File::find("assets/PDF/myFile.pdf");
$fileName = "myFile.pdf";
return SS_HTTPRequest::send_file($filedata, $fileName, 'application/pdf');
}
每當你得到一個「500錯誤」回到你需要改變開發模式,會給你一個錯誤,將可能幫助你解決或someelse在這裏幫助你解決 – Barry
嗨。謝謝你回答這麼快。我處於開發模式..在單擊按鈕後重新加載頁面後發現「真實」錯誤:[可恢復錯誤]類SS_HTTPResponse的對象無法轉換爲字符串。不幸的是,仍然不知道該怎麼辦:(你能幫我嗎? – iraira
@iraira我遇到了同樣的問題。你找到了解決方案嗎? –