Hallo,
ich möchte gerne den/die Namen der Kategorie von mae_event_categories ausgeben, und würde mich freuen wenn ich etwas Hilfestellung bekomme,
Ich gestehe diesen Code, den es schon sehr lange gibt, weis nicht mehr woher, nur das nicht selber geschrieben habe, glaube aber in Etwa verstanden zu haben das da passiert ,

Also, dieser folgende code im Template gibt den Titel des Eventkalenders im HTML aus:

Code:
Mein wunderbares Event: <?php $this->import('Database'); $result = $this->Database->prepare("SELECT * FROM tl_calendar WHERE id='$this->pid'")->execute(); ?> <?php echo $result->title; ?>
Ergibt: Mein wunderbares Event: "Freude Friede Eierkuchen"


Nun habe ich versucht diesen Code mit meinen rudimentären Kenntnissen zu Modifizieren um den Namen der Kategorie von mae_event_categories auszugeben, doch garnis erscheint:
Code:
Kategorie: <?php $this->import('Database'); $result = $this->Database->prepare("SELECT * FROM tl_mae_event_cat WHERE id='$this->pid'")->execute(); ?> <?php echo $result->title; ?>
Es gibt mehrer Kategorien, daher vermute ich das ich eine array Abfrage machen müsste?
???

Doch wie macht man das fragt dtptiger.


Das folgende ist die dca von mae_event_cat, aus der ich vermute die Infos zu entnehmen sind um eine Arrayabfrage zu machen, oder?

PHP-Code:

$GLOBALS
['TL_DCA']['tl_mae_event_cat'] = array
(

    
// Config
    
'config' => array
    (
        
'dataContainer'               => 'Table',
        
'enableVersioning'            => false,
        
'sql' => array
        (
            
'keys' => array
            (
                
'id' => 'primary',
                
'alias' => 'index'
            
)
        ),
        
'backlink'                    => 'do=calendar',
        
'ondelete_callback'           => array(
            array(
'tl_mae_event_cat''checkPermission'),
            array(
'tl_mae_event_cat''onDelete')
        ),
        
'onload_callback' => array
        (
            array(
'tl_mae_event_cat''checkPermission')
        ),
    ),

    
// List
    
'list' => array
    (
        
'sorting' => array
        (
            
'mode'                    => 1,
            
'fields'                  => array('title'),
            
'flag'                    => 1,
            
'panelLayout'             => 'search'
        
),
        
'label' => array
        (
            
'fields'                  => array('title'),
            
'format'                  => '%s'
        
),
        
'global_operations' => array
        (
            
'all' => array
            (
                
'label'               => &$GLOBALS['TL_LANG']['MSC']['all'],
                
'href'                => 'act=select',
                
'class'               => 'header_edit_all',
                
'attributes'          => 'onclick="Backend.getScrollOffset();" accesskey="e"'
            
)
        ),
        
'operations' => array
        (
            
'edit' => array
            (
                
'label'               => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['edit'],
                
'href'                => 'act=edit',
                
'icon'                => 'edit.gif'
            
),
            
'copy' => array
            (
                
'label'               => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['copy'],
                
'href'                => 'act=copy',
                
'icon'                => 'copy.gif'
            
),
            
'delete' => array
            (
                
'label'               => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['delete'],
                
'href'                => 'act=delete',
                
'icon'                => 'delete.gif',
                
'attributes'          => 'onclick="if(!confirm(\'' $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
            
),
            
'show' => array
            (
                
'label'               => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['show'],
                
'href'                => 'act=show',
                
'icon'                => 'show.gif'
            
)
        )
    ),

    
// Select
    
'select' => array
    (
        
'buttons_callback' => array()
    ),

    
// Edit
    
'edit' => array
    (
        
'buttons_callback' => array()
    ),

    
// Palettes
    
'palettes' => array
    (
        
'__selector__'                => array(''),
        
'default'                     => '{title_legend},title,alias;{layout_legend},cssId,cssClass'
    
),

    
// Subpalettes
    
'subpalettes' => array
    (
        
''                            => ''
    
),

    
// Fields
    
'fields' => array
    (
        
'id' => array
        (
            
'sql'                     => "int(10) unsigned NOT NULL auto_increment"
        
),
        
'tstamp' => array
        (
            
'sql'                     => "int(10) unsigned NOT NULL default '0'"
        
),
        
'title' => array
        (
            
'label'                   => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['title'],
            
'exclude'                 => false,
            
'search'                  => true,
            
'inputType'               => 'text',
            
'eval'                    => array('mandatory'=>true'maxlength'=>255'tl_class'=>'w50'),
            
'sql'                     => "varchar(255) NOT NULL default ''"
        
),
        
'alias' => array
        (
            
'label'                   => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['alias'],
            
'exclude'                 => false,
            
'search'                  => true,
            
'inputType'               => 'text',
            
'eval'                    => array('mandatory'=>false'maxlength'=>50'rgxp'=>'alias''tl_class'=>'w50''unique'=>true),
            
'save_callback'           => array(
                array(
'tl_mae_event_cat''generateAlias')
            ),
            
'sql'                     => "varchar(50) NOT NULL default ''"
        
),
        
'cssId' => array
        (
            
'label'                   => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssId'],
            
'exclude'                 => true,
            
'inputType'               => 'text',
            
'eval'                    => array('mandatory'=>false'maxlength'=>60'tl_class'=>'w50'),
            
'sql'                     => "varchar(60) NOT NULL default ''"
        
),
        
'cssClass' => array
        (
            
'label'                   => &$GLOBALS['TL_LANG']['tl_mae_event_cat']['cssClass'],
            
'exclude'                 => true,
            
'inputType'               => 'text',
            
'eval'                    => array('mandatory'=>false'maxlength'=>255'tl_class'=>'w50'),
            
'sql'                     => "varchar(255) NOT NULL default ''"
        
)
    )
);

class 
tl_mae_event_cat extends Backend
{

    
/**
     * Import the back end user object
     */
    
public function __construct()
    {
        
parent::__construct();
        
$this->import('BackendUser''User');
    }


    
/**
     * Check permissions to edit table tl_mae_event_cat
     */
    
public function checkPermission()
    {
        if (!
$this->User->isAdmin && !$this->User->maeEventCat)
        {
            
$this->log('Not enough permissions to manage event categories'__METHOD__TL_ERROR);
            
$this->redirect('contao/main.php?act=error');
        }
    }
    
    
/**
     * Auto-generate a category alias if it has not been set yet
     *
     * @param mixed         $varValue
     * @param DataContainer $dc
     *
     * @return string
     *
     * @throws Exception
     */
    
public function generateAlias($varValueDataContainer $dc)
    {
        
$autoAlias false;
        
// Generate an alias if there is none
        
if ($varValue == '')
        {
            
$autoAlias true;
            
$varValue StringUtil::generateAlias($dc->activeRecord->title);
        }
        
$objAlias $this->Database->prepare("SELECT id FROM tl_mae_event_cat WHERE alias=?")
                                   ->
execute($varValue);
        
// Check whether the category alias exists
        
if ($objAlias->numRows 1)
        {
            if (!
$autoAlias)
            {
                throw new 
Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
            }
            
$varValue .= '-' $dc->id;
        }
        return 
$varValue;
    }


    
/**
     * delete references in tl_calendar_events and tl_module
     */
    
public function onDelete(DataContainer $dc)
    {
        if (!
$dc->id)
        {
            return;
        }

        
/*
         * delete references in tl_calendar_events
         */
        
$objEvent $this->Database->prepare("SELECT id, categories FROM tl_calendar_events WHERE categories != ''")
            ->
execute();
        while(
$objEvent->next()) {
            
$arrCats unserialize($objEvent->categories);
            if(
is_array($arrCats) && ($key array_search($dc->id$arrCats)) !== false) {
                unset(
$arrCats[$key]);
                
$updCatVal count($arrCats) > serialize($arrCats) : "";
                
$this->Database->prepare("UPDATE tl_calendar_events SET categories=? WHERE id=?")
                    ->
execute(array($updCatVal$objEvent->id));
            } 
// events having this category
        
// events having categories


        /*
         * delete references in tl_module
         */
        
$objMod $this->Database->prepare("SELECT id, event_categories FROM tl_module WHERE event_categories != ''")
            ->
execute();
        while(
$objMod->next()) {
            
$arrCats unserialize($objMod->event_categories);
            if(
is_array($arrCats) && ($key array_search($dc->id$arrCats)) !== false) {
                unset(
$arrCats[$key]);
                
$updCatVal count($arrCats) > serialize($arrCats) : "";
                
$this->Database->prepare("UPDATE tl_module SET event_categories=? WHERE id=?")
                    ->
execute(array($updCatVal$objMod->id));
            } 
// modules having this category
        
// modules having categories
    
// onDelete()
// class tl_mae_event_cat