本文整理汇总了PHP中Export::getSampleText方法的典型用法代码示例。如果您正苦于以下问题:PHP Export::getSampleText方法的具体用法?PHP Export::getSampleText怎么用?PHP Export::getSampleText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Export
的用法示例。
在下文中一共展示了Export::getSampleText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadSample
public static function downloadSample($model, $config = null)
{
$import = new Import($model, $config);
$data = $import->model->find();
$header = [];
$sample = [];
$modelCols = $import->model->tableSchema->columns;
foreach ($import->columns as $key => $col) {
$col = is_string($col) ? ['type' => $col] : $col;
switch ($col['type']) {
case "pk":
case "default":
$header[] = $key;
if (isset($col['sample'])) {
$sample[] = $col['sample'];
} else {
if (isset($modelCols[$key])) {
if ($col['type'] == 'pk') {
$sample[] = '';
} else {
if (isset($data)) {
$sample[] = $data->{$key};
} else {
$sample[] = Export::getSampleText($modelCols[$key]);
}
}
} else {
$sample[] = "text";
}
}
break;
case "lookup":
if (@$col['show'] !== false) {
$header[] = $key;
if (isset($col['sample'])) {
$sample[] = $col['sample'];
} else {
$sample[] = 'text';
}
}
break;
}
}
$writer = WriterFactory::create(Type::XLSX);
$writer->openToBrowser("import-" . Helper::camelToSnake($model) . '.xlsx');
// stream data directly to the browser
$writer->addRows([$header, $sample]);
// add multiple rows at a time
$writer->close();
}