我的 Controller 中有一个方法
public function download($filepath){
$download_path = $_SERVER['DOCUMENT_ROOT']. "mediabox/import";
$file = $download_path + $filepath ;
if(!$file) die("I'm sorry, you must specify a file name to download.");
if(eregi("\.ht.+", $file)) die("I'm sorry, you may not download that file.");
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
$type = filetype($file);
header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
readfile($file);
}
在我看来我有一个链接
<a target='_blank' class='download_dialog' onClick="???">
我想调用我的 Controller 的下载方法 onclick 事件的链接。 这样做好吗? 我该怎么做 ? 谢谢
最佳答案
你可以试试:
<a target='_blank' class='download_dialog' href="<?php echo base_url();?>YourControllerName/download">
(是的,您需要为 base_url 使用 url 帮助程序)或在某些 javascript onClick 调用中使用该 url,但我不确定这是否是最适合您的解决方案。
关于php - 从 View 调用 Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9789671/