我正在使用CakePHP 2.x,並在IIS上本地運行它。我正在關注Exporting data to CSV the CakePHP way的教程,並且出現錯誤。輸出CSV時缺少查看文件
我輸入的URL是這樣的:http://myproject.localhost/territory/spreadsheet.csv
我Router::parseExtensions('csv');
在app\Config\routes.php
這裏的第一件事情是我的控制器:
`類TerritoryController擴展的AppController { 公共$ useTable ='ezrep_territory';
public $paginate = array('limit' => 50);
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->deny('index');
}
public function Index()
{
// ... snip ...
}
public function Spreadsheet()
{
$data = $this->Territory->find(
'all',
array(
'conditions' => array('Territory.ez' => $this->ez),
'fields' => array('territory','terrcode','terrdesc'),
'contain' => false
));
$headers = array(
'Territory'=>array(
'territory' => 'Territory ID',
'terrcode' => 'Terr Code',
'terrdesc' => 'Terr Desc'
)
);
array_unshift($data,$headers);
$this->set(compact('data'));
}
} `
在app\View\Layouts\csv
,我有一個文件default.ctp
:
<?php echo $content_for_layout; ?>
而在app\View\Territory
,我有一個文件spreadsheet.ctp
:
// Loop through the data array
foreach ($data as $row)
{
// Loop through every value in a row
foreach ($row['Territory'] as &$value)
{
// Apply opening and closing text delimiters to every value
$value = "\"".$value."\"";
}
// Echo all values in a row comma separated
echo implode(",",$row['Territory'])."\n";
}
當我去http://myproject.localhost/territory/spreadsheet.csv
,我得到的似乎是通過app\View\Layouts\default.ctp
一個錯誤有一個頁面渲染:
View file "C:\zproj\ezrep40\app\View\Territory\csv\spreadsheet.ctp" is missing.
和 Error: An Internal Error Has Occurred.
我在做什麼錯?