我正在使用 CakePHP 2.x,并在 IIS 上本地运行它。我正在按照CakePHP方式将数据导出到CSV的教程进行操作,但出现错误。
我输入的 URL 是这样的:http://myproject.localhost/territory/spreadsheet.csv
我有Router::parseExtensions('csv');
作为第一件事app\Config\routes.php
这是我的控制器:
`class TerritoryController 扩展 AppController { public $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.
我究竟做错了什么?