Customize Export to Html

Hello everyone

I have the following code working perfectly in version 2024.15

// Extender la clase ExportHtml original
class MyExportHtml extends ExportHtml {

    // Sobrescribir el método exportFieldValue para organizar las imágenes en múltiples campos
    public function exportFieldValue(DbField $fld): mixed {
        // Aplicar el mismo estilo para los campos que contienen fotos
        if (in_array($fld->Name, ["Fotos_perimetro", "Fotos_electronica", "Fotos_internas", "Fotos_especificas"])) {
            // Obtener el valor exportado original del campo
            $exportValue = parent::exportFieldValue($fld);

            // Modificar el HTML para organizar las imágenes en horizontal usando flexbox
            // y aplicar un tamaño fijo a las imágenes
            $photoHtml = '<style>
                            @media print {
                                .photo-container img {
                                    width: 200px;
                                    height: 200px;
                                    object-fit: cover;
                                }
                            }
                        </style>
                        <div class="photo-container" style="display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start;">' . 
                         preg_replace('/<img([^>]*)>/i', '<img$1 style="width: 200px; height: 200px; object-fit: cover;"/>', $exportValue) .
                         '</div>';

            // Devolver el valor modificado del campo de fotos
            return $photoHtml;
        } else {
            // Para otros campos, devolver el valor normal
            return parent::exportFieldValue($fld);
        }
    }
}


// Reemplazar la clase predeterminada de exportación HTML
Config("EXPORT_CLASSES.html", "MyExportHtml");

in the new phpmaker 2025.1

Any idea to solve doesn’t work

You need to describe “doesn’t work” in more detail, enable Debug and run again, post the error messages in the log.

Fatal error : Declaration of PHPMaker2025\Analytics\MyExportHtml::exportFieldValue($fld) must be compatible with PHPMaker2025\Analytics\ExportHtml::exportFieldValue(PHPMaker2025\Analytics\DbField $fld): mixed in C:\xampp\htdocs\src\userfn.php on line 415

As the error message said, you need to use DbField $fld.

Thanks for responding

I adjust the global code and when I export the table in view it gives me the following message
Invalid Parameter: Table = vulnerabilidad, export type = html

You may post your code for discussion.

It was corrected by registering the class like this

in case anyone requires it

// Registrar la clase de exportación
$EXPORT = [
    "html" => "PHPMaker2025\\Analytics\\MyExportHtml" // Asegúrate de usar el namespace correcto
];

Thank you