2017-05-09 36 views
1

我是新來的zend框架1.12.19,現在我要生成一個excel文件。我完成了代碼。在我需要將佈局設置爲無佈局。如何在zend framwork 1.12.19中設置disableLayout?

我已經寫了上面的內容來做到這一點。但它不起作用,它給我一些錯誤。

set_time_limit(0); 

     $filename = '../data/uploaded-files/excel-uploaded/FILE.xls'; 
     $realPath = realpath($filename); 
     if (false === $realPath) 
     { 
      touch($filename); 
      chmod($filename, 0777); 
     } 

     $filename = realpath($filename); 
     $handle = fopen($filename, "w"); 
     $finalData = array(); 
     $data = array 
        (
         array("Volvo",22,18), 
         array("BMW",15,13), 
         array("Saab",5,2), 
         array("Land Rover",17,15) 
        ); 

     foreach ($data AS $row) 
     { 

      $finalData[] = array(
       utf8_decode($row[0]), // For chars with accents. 
       utf8_decode($row[1]), 
       utf8_decode($row[2]), 
      ); 
     } 
     foreach ($finalData AS $finalRow) 
     { 
      fputcsv($handle, $finalRow, "\t"); 
     } 
     fclose($handle); 
     $this->_helper->layout->disableLayout(); 
    $this->_helper->viewRenderer->setNoRender(TRUE); 
     $this->getResponse()->setRawHeader("Content-Type: application/vnd.ms-excel; charset=UTF-8") 
      ->setRawHeader("Content-Disposition: attachment; filename=otros-fondos.xls") 
      ->setRawHeader("Content-Transfer-Encoding: binary") 
      ->setRawHeader("Expires: 0") 
      ->setRawHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0") 
      ->setRawHeader("Pragma: public") 
      ->setRawHeader("Content-Length: " . filesize($filename)) 
      ->sendResponse(); 
     readfile($filename); exit(); 

錯誤: 動作助手的名字佈局沒有找到

+0

如果您可以向我們展示更多代碼,例如您的控制器的整個操作,這將有所幫助。另外,沒有ZF 1.2。檢查'Zend/Version.php'是否是你正在使用的框架的實際版本。 –

+0

對不起,錯字,其v1.12.19 – AWE

+0

我更新了我的代碼。 – AWE

回答

0

這是一個小的差異,以你的代碼,但是這是你可以嘗試在你的動作做到:

$this->_helper->layout()->disableLayout(); 
$this->_helper->viewRenderer->setNoRender(true); 

佈局助手可能需要括號。

編輯

因爲它看起來像插件無法找到:你確定它存在於Zend/Layout/Controller/Action/Helper/Layout.php,它被自動加載?

你的application.ini的內容是什麼?

+0

不工作。同樣的錯誤。 – AWE

+0

我這麼認爲。 require_once('Zend/Loader/Autoloader.php'); require_once('../../library/ZendFramework-1.12.19/library/Zend/Layout/Controller/Action/Helper/Layout.php'); – AWE

+0

你可以發佈整個控制器嗎?也許我可以爲你找點東西。另外,'application.ini'的內容是什麼? –