hallo,
Ich habe mir mit "kickstarter" eine eigene "Extension" gebastelt. Letztendlich will ich nur eine Befüllte MySQL-Tabelle auslesen ...
Diese Dokumentation fand ich recht hilfreich.:
http://wiki.typo3.org/index.php/Extension_Development%2C_using_HTML-Templates
Die Extension habe ich aber nach dieser Anleitung erstellt:
http://www.traum-projekt.com/forum/73-workshops-und-tutorials/101411-workshop-typo3-extension-programmierung.html
hier jetzt erstmal mein CODE (der eigentlich 1 zu 1 aus der ersten Dokumentation kommt):
<?php
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_mbartikelliste_pi1 extends tslib_pibase {
var $prefixId = 'tx_mbartikelliste_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_mbartikelliste_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'mb_artikelliste'; // The extension key.
var $pi_checkCHash = true;
function main($content, $conf) {
$this->conf = $conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
#ein paar Vorbelegungen
$this->id=$GLOBALS['TSFE']->id;
$this->template=$this->cObj->fileResource('EXT:mb_artikelliste/template.html');
$content = $this->mb_liste();
return $this->pi_wrapInBaseClass($content);
}
function mb_liste() {
#unser Subpart
// Get the parts out of the template
$template['total'] = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE###');
$template['item'] = $this->cObj->getSubpart($template['total'],'###ITEM###');
#Datensätze holen nach product_kind
$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*', #select
'tx_mbartikelliste_artikeltabelle', #from
'hidden=0 and deleted=0 and pid='.$this->id, #where
$groupBy='product_kind',
$orderBy='product_kind',
$limit='');
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
// Fill marker
$markerArray['###MARKER1###'] = $row['article_name'];
$markerArray['###MARKER2###'] = $row['product_kind'];
var_dump($row['article_name']);
// Add subpart into a string
$content_item .= $this->cObj->substituteMarkerArrayCached($template['item'], $markerArray);
}
// Fill subpart marker
$subpartArray['###CONTENT###'] = $content_item;
var_dump($content_item);
return $this->cObj->substituteMarkerArrayCached($template['total'], array(), $subpartArray);
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mb_artikelliste/pi1/class.tx_mbartikelliste_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mb_artikelliste/pi1/class.tx_mbartikelliste_pi1.php']);
}
?>
Hier das Template (1 zu 1 aus der Dokumentation):
<h3>TEMPLATE</h3>
<em>This is a more complex html template</em>
<!-- ###TEMPLATE### begin -->
<table>
<!-- ###CONTENT### -->
<!-- ###ITEM### -->
<tr>
<td>###MARKER1###</td><td>###MARKER2###</td>
</tr>
<!-- ###ITEM### -->
<!-- ###CONTENT### -->
</table>
<!-- ###TEMPLATE### end -->
Doch leider funktioniert es nicht so wie ich will 🙁
Die reine SQL-Abfrage klapp ganz gut, und wird auch in der Schleife gut verarbeitet, denn wenn ich in der Schleife ein var_dump($row['article_name']); auführe, werden mir die richtigen Daten ausgespuckt, ... wobei es mich irritiert, warum immer "string(#Zeichenlänge#) "Eintrag"" dasteht anstatt nur der Eintrag. In dem Template wird aber nichts ausgegeben.
sobald ich aber an letzter Stelle der While-Schleife ein var_dump($content_item); mache, wirft er mir für jedes Item nur noch string(0) "" raus.
Daher vermute ich, dass irgend etwas an dieser Zeile in der While-Schleife nicht stimmt:
$content_item .= $this->cObj->substituteMarkerArrayCached($template['item'], $markerArray);
Kennt sich hier jemand damit aus und kann mir weiterhelfen?