Modul im Backend

Ein Modul im Backend zu programmieren ist nicht ganz einfach. Der ExtensionBuilder in TYPO3 4.7 generiert zwar jede Menge Code, doch hat das bei mir nicht funktioniert. Also habe ich das Backendmodul von Hand angelegt. Als Beispiel ist dies hier ein Exportmodul.

Controller

Ein "gewöhnlicher" Controller in Classes/Controller/ExportController.php

<?php
class Tx_Rsysworkbook_Controller_ExportController extends Tx_Extbase_MVC_Controller_ActionController {

    // ------------------------------------------------------------
    // properties
    // ------------------------------------------------------------
   
    protected $settings = array();
   
    /**
     * frontendUserRepository
     *
     * @var Tx_Rsysworkbook_Domain_Repository_FrontendUserRepository
     */
    protected $frontendUserRepository;
   
    protected function initializeAction() {
        $this->frontendUserRepository = t3lib_div::makeInstance('Tx_Rsysworkbook_Domain_Repository_FrontendUserRepository');
       
        $configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_BackendConfigurationManager');
        $this->settings = $configurationManager->getConfiguration(
                $this->request->getControllerExtensionName(),
                $this->request->getPluginName()
        );
        $this->settings = $this->settings['settings'];
    }
   
   

    /**
     * action list
     *
     * @return void
     */
    public function indexAction() {
        // just renders template
    }

   
    /**
     * action export
     *
     * @return void
     */
    public function exportAction() {

        // do all the export stuff here...

        // ----------------------------------------
        // download csv file
        // ----------------------------------------
        // prepare infos
        $cType = 'application/csv';
        $fileLen = filesize($exportFileName);
        $headers = array(
                'Pragma' => 'public',
                'Expires' => 0,
                'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
                'Cache-Control' => 'public',
                'Content-Description' => 'File Transfer',
                'Content-Type' => $cType,
                'Content-Disposition' => 'attachment; filename="'.$fname.'"',
                'Content-Transfer-Encoding' => 'binary',
                'Content-Length' => $fileLen
        );
   
        // send headers
        foreach ($headers as $header => $data)
            $this->response->setHeader($header, $data);
   
        $this->response->sendHeaders();
   
        // send file
        @readfile($exportFileName);
        exit;
       
    }
       
}
?>

Modul im Backend anlegen

ext_tables.php


if (TYPO3_MODE === 'BE') {

    /**
     * Registers a Backend Module
     */
    Tx_Extbase_Utility_Extension::registerModule(
        $_EXTKEY,
        'web',       // Make module a submodule of 'web'
        'export',    // Submodule key
        '',          // Position
        array(
            'Export' => 'index,show,export'
        ),
        array(
            'access' => 'user,group',
            'icon'   => 'EXT:' . $_EXTKEY . '/ext_icon.gif',
            'labels' => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_export.xml',
        )
    );

}

Konfiguration Typoscript

Setup

# Module configuration
module.tx_rsysworkbook {
    persistence {
        storagePid = {$module.tx_rsysworkbook.persistence.storagePid}
    }
    view {
        templateRootPath = {$module.tx_rsysworkbook.view.templateRootPath}
        partialRootPath = {$module.tx_rsysworkbook.view.partialRootPath}
        layoutRootPath = {$module.tx_rsysworkbook.view.layoutRootPath}
    }
}

Constants

Ich habe den Template Pfad nach Resources/Private/Backend gelegt:

module.tx_rsysworkbook {
    view {
        # cat=module.tx_rsysworkbook/file; type=string; label=Path to template root (BE)
        templateRootPath = EXT:rsysworkbook/Resources/Private/Backend/Templates/
        # cat=module.tx_rsysworkbook/file; type=string; label=Path to template partials (BE)
        partialRootPath = EXT:rsysworkbook/Resources/Private/Backend/Partials/
        # cat=module.tx_rsysworkbook/file; type=string; label=Path to template layouts (BE)
        layoutRootPath = EXT:rsysworkbook/Resources/Private/Backend/Layouts/
    }
    persistence {
        # cat=module.tx_rsysworkbook//a; type=string; label=Default storage PID
        storagePid = 29
    }
}

Templates

Resources/Private/Backend/Templates/Index.html

<f:layout name="Default" />
<f:section name="main">
<h2 class="be_header">Workbook Daten Export</h2>
<b><f:flashMessages /></b>
CSV Download der Ergebnisse (Feldtrenner | )<br>
<br>
<f:link.action action="export">=> Download</f:link.action>
</f:section>

Layout

Resources/Private/Backend/Layouts/Default.html

 <f:be.container>
    <div class="typo3-fullDoc">
        <div id="typo3-docheader">
            <div id="typo3-docheader-row1">
                <div class="buttonsleft">

                </div>
                <div class="buttonsright">
                    <f:be.buttons.shortcut />
                </div>
            </div>
            <div id="typo3-docheader-row2">
                <div class="docheader-row2-left">
                    <f:be.buttons.csh />
                    <f:be.menus.actionMenu>
                        <f:be.menus.actionMenuItem label="Overview" controller="" action="index" />                            
                    </f:be.menus.actionMenu>
                </div>
                <div class="docheader-row2-right">
                    <f:be.pagePath />
                    <f:be.pageInfo />
                </div>
            </div>

        </div>
        <div id="typo3-docbody">
            <div id="typo3-inner-docbody">
                <f:flashMessages renderMode="div" />
                <f:render section="main" />
            </div>
        </div>
    </div>
</f:be.container>

 Funktion

Bei Klick auf den Link <f:link.action action="export">=> Download</f:link.action> aus dem Template Resources/Private/Backend/Templates/Index.html wird die exportAction aufgerufen. Diese rendert kein Template sondern gibt direct ein Download File an den Browser und bricht das rendern mit exit ab.

Erstellt: 09/2012| Geändert: 10/2015