[TYPO3-german] phpcode
Thomas Bartholomäus
tb at didymus.de
Tue Mar 11 17:06:24 CET 2008
Hallo,
den unten stehenden Code habe ich aus dem Kochbuch von Hanser, Seite
648.
Den soll ich laut Buch in
typo3conf/ext/musicdb/pi1/class.tx_meineextension_pi1.php schreiben und
zwar in die main() -Methode. Aber wo genau. danke.
Die sieht bisher so aus:
/////////////////////////////////////////////////////////////////////////
/**
* Main method of your PlugIn
*
* @param string $content: The content of the PlugIn
* @param array $conf: The PlugIn Configuration
* @return The content that should be displayed on the website
*/
function main($content,$conf) {
switch((string)$conf['CMD']) {
case 'singleView':
list($t) = explode(':',$this->cObj->currentRecord);
$this->internal['currentTable']=$t;
$this->internal['currentRow']=$this->cObj->data;
return $this->pi_wrapInBaseClass($this->singleView($content,$conf));
break;
default:
if (strstr($this->cObj->currentRecord,'tt_content')) {
$conf['pidList'] = $this->cObj->data['pages'];
$conf['recursive'] = $this->cObj->data['recursive'];
}
return $this->pi_wrapInBaseClass($this->listView($content,$conf));
break;
}
}
/////////////////////////////////////////////////////////////////
und jetzt der code aus dem Buch.
//////////////////////////////////////////////////////////////////////
# Template-Datei einlesen
$this->templateCode = $this->cObj->fileResource($conf['templateFile']);
# Bereich im Template auswählen
$template['total'] =
$this->cObj->getSubpart($this->templateCode,'###SINGLEVIEW###');
# Inhalt für die einzelnen Marker in das Marker-Array schreiben -
# dabei für die Field-Werte die entsprechende Übersetzung mittels
# pi_getLL() holen.
$markerArray['###FIELD1###'] = $this->pi_getLL('FIELD1');
$markerArray['###VALUE1###'] = 'VALUE1';
$markerArray['###FIELD2###'] = $this->pi_getLL('FIELD2');
$markerArray['###VALUE2###'] = 'VALUE2';
# Nun werden alle Marker im Template ersetzt und das ersetzte Template
# in die Ausgabe-Variable $content geschrieben
$content = $this->cObj->substituteMarkerArrayCached($template['total'],
$markerArray);
# Die Ausgabe-Variable wird schließlich zurückgegeben.
return $content;
# Template-Datei einlesen
$this->templateCode = $this->cObj->fileResource($conf['templateFile']);
# Bereich im Template auswählen
$template['total'] =
$this->cObj->getSubpart($this->templateCode,'###LISTVIEW###');
# Subpart auswählen
$template['item'] = $this->cObj->getSubpart($template['total'],
'###ITEM###');
# Ergebnisliste zusammenstellen
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
# Marker-Array fullen
$markerArray['###VALUE1###'] = $row['value1'];
$markerArray['###VALUE2###'] = $row['value2'];
# Marker ersetzen
$content_item .=
$this->cObj->substituteMarkerArrayCached($template['item'],
$markerArray);
}
# Subpart ersetzen
$subpartArray['###CONTENT###'] = $content_item;
$content = $tis->cObj->substituteMarkerArrayCached($template['total'],
array(), $subpartArray);
# Die Ausgabe-Variable wird schließlich zurückgegeben
return $content;
/////////////////////////////////////////////////////////////////////////
danke
thomas
More information about the TYPO3-german
mailing list