У меня есть Router :: parseextensions ('csv'); как первое в приложении \ config \ routes.php
Вот мой контроллер: < /p>
`class terrioritycontroller extcontroller
{
public $ usetable = 'ezrep_territory'; < /p>
Код: Выделить всё
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'));
}
< /code>
}
`< /p>
in app \ view \ mayouts \ csv < /code>, i Иметь файл default.ctp < /code>: < /p>
и в приложении \ view \ territory , у меня есть файл Spreadsheat.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";
}
Код: Выделить всё
View file "C:\zproj\ezrep40\app\View\Territory\csv\spreadsheet.ctp" is missing.< /code>
и
Error: An Internal Error Has Occurred.Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/108 ... utting-csv
Мобильная версия