Exista un sistem general de import de date. Este construit ca modul in /frontend/modules/importer.
Un importer care importa date dintr-un ipotetic soft “Gigi” are urmatoarele componente:
- un controller /frontend/modules/importer/controllers/ImportGigiController.php
- cate un view pentru fiecare tip de import in /frontend/modules/importer/views/import-gigi care contine formularul de import
- cate un action (in controller) pentru fiecare tip de import
- controller-ul trebuie inregistrat in /frontend/modules/importer/ImporterModule.php
- importer-ele inregistrate in /frontend/modules/importer/models/GeneralImporter.php > getImportSources() , pe o constanta FORMAT_GIGI = x unde x = max(FORMAT_xxx)+1
In GeneralImporter.php > getImportSources() se inregistreaza asa:
// self::FORMAT_XXX is the DISTINCT constant defined above in the same class
self::FORMAT_NATIVE => [
// denumirea provider-ului de date
'caption' => Yii::t('app', 'Native'),
// descrierea provider-ului de date
'description' => Yii::t('app', 'Import from MAX BA export files'),
// one of these entries for each import type
'importTypes' => [
1 => [
// the name of the specific importer
'caption' => Yii::t('app', 'Balance'),
// the description of the specific importer
'description' => Yii::t('app', 'Company initial balance importer'),
// the controller where it resides; all importers of a provider have the same controller
'controller' => 'importer/import-native',
// the action where its code is
'action' => 'index',
// a "discerner" function used to validate if the selected file is
// indeed correct, and also for auto-detection
// It must return 100 for success of 0 for failure of detection/match
'discerner' => function ($tmpName, $originalName, $rows) {
$pi = pathinfo($originalName);
$extension = trim(strtoupper($pi['extension']));
$matchPercentage =
($extension == "XLS" || $extension == "XLSX") && false
?100 :0;
return $matchPercentage;
}
],
]
],
In rest, vedeti si copiati 🙂
Categories: HINTS (tehnice), Tutoriale / Reguli / Best practices |
Leave a Reply
[TOP]