PHP-Zend框架发送文件
我试图在Zend Framework PHP应用程序中向浏览器发送一个文件。我在这里找到了一个行动助手- 在我的控制器中,我有一个这样的动作PHP-Zend框架发送文件,php,zend-framework,Php,Zend Framework,我试图在Zend Framework PHP应用程序中向浏览器发送一个文件。我在这里找到了一个行动助手- 在我的控制器中,我有一个这样的动作 public function downloadfileAction() { //get the file name and strip out all white spaces $title = preg_replace('/\s+/', '', $this->getRequest()->getParam('title'));
public function downloadfileAction()
{
//get the file name and strip out all white spaces
$title = preg_replace('/\s+/', '', $this->getRequest()->getParam('title'));
//create the file path
$path = 'downloads/'.$title.'.pdf';
//call the action helper to send the file to the browser
$this->_helper->SendFile->sendFile($path, 'application/x-pdf');
}
我的文件位于我的公用文件夹中,即MyApp/public/downloads/myFile.pdf
当我运行该操作时,我得到一个视图文件未找到错误,并且下载未启动
exception 'Zend_View_Exception' with message 'script 'myController/downloadfile.phtml' not found ...
有人能指出我做错了什么吗?这是一个关于脚本-(视图)-文件的错误,无法找到。因为发送输出时不需要一个 尝试通过以下方式禁用它:
public function downloadfileAction()
{
//get the file name and strip out all white spaces
$title = preg_replace('/\s+/', '', $this->getRequest()->getParam('title'));
//create the file path
$path = 'downloads/'.$title.'.pdf';
//call the action helper to send the file to the browser
$this->_helper->SendFile->sendFile($path, 'application/x-pdf');
$this->_helper->viewRenderer->setNoRender();
}
很高兴听到,没问题!:)别忘了接受答案,谢谢。:)