Bin immer noch kein Schritt weiter. Habe mir heute die Core Api reingezogen. Ist ja nicht schlecht, aber was nützen mir die Funktionen (und Beschreibungen) wenn mir irgendwie immer noch die zusammenhänge fehlen.
Also dann nochmal: Habe kleine Testextension mit dem kickstarter erstellt.
Hier mal der SQL Code
#
# Table structure for table 'tx_test_tabelle1'
#
CREATE TABLE tx_test_tabelle1 (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
testfeld1 tinytext NOT NULL,
verknuepfung int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
#
# Table structure for table 'tx_test_test2'
#
CREATE TABLE tx_test_test2 (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
tstamp int(11) DEFAULT '0' NOT NULL,
crdate int(11) DEFAULT '0' NOT NULL,
cruser_id int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
tab2_feld1 tinytext NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
und hier mal die class.tx
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_test_pi1 extends tslib_pibase {
var $prefixId = 'tx_test_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_test_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'test'; // The extension key.
var $pi_checkCHash = TRUE;
var $verknuepfungCache = array();
/**
* [Put your description here]
*/
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;
}
}
/**
* [Put your description here]
*/
function listView($content,$conf) {
$this->conf=$conf; // Setting the TypoScript passed to this function in $this->conf
$this->pi_setPiVarDefaults();
$this->pi_loadLL(); // Loading the LOCAL_LANG values
$lConf = $this->conf['listView.']; // Local settings for the listView function
if ($this->piVars['showUid']) { // If a single element should be displayed:
$this->internal['currentTable'] = 'tx_test_tabelle1';
$this->internal['currentRow'] = $this->pi_getRecord('tx_test_tabelle1',$this->piVars['showUid']);
$content = $this->singleView($content,$conf);
return $content;
} else {
$items=array(
'1'=> $this->pi_getLL('list_mode_1','Mode 1'),
'2'=> $this->pi_getLL('list_mode_2','Mode 2'),
'3'=> $this->pi_getLL('list_mode_3','Mode 3'),
);
if (!isset($this->piVars['pointer'])) $this->piVars['pointer']=0;
if (!isset($this->piVars['mode'])) $this->piVars['mode']=1;
// Initializing the query parameters:
list($this->internal['orderBy'],$this->internal['descFlag']) = explode(':',$this->piVars['sort']);
$this->internal['results_at_a_time']=t3lib_div::intInRange($lConf['results_at_a_time'],0,1000,3); // Number of results to show in a listing.
$this->internal['maxPages']=t3lib_div::intInRange($lConf['maxPages'],0,1000,2);; // The maximum number of "pages" in the browse-box: "Page 1", "Page 2", etc.
$this->internal['searchFieldList']='testfeld1';
$this->internal['orderByList']='uid,testfeld1';
// Get number of records:
$res = $this->pi_exec_query('tx_test_tabelle1',1);
list($this->internal['res_count']) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
// Make listing query, pass query to SQL database:
$res = $this->pi_exec_query('tx_test_tabelle1');
$this->internal['currentTable'] = 'tx_test_tabelle1';
// Put the whole list together:
$fullTable=''; // Clear var;
# $fullTable.=t3lib_div::view_array($this->piVars); // DEBUG: Output the content of $this->piVars for debug purposes. REMEMBER to comment out the IP-lock in the debug() function in t3lib/config_default.php if nothing happens when you un-comment this line!
// Adds the mode selector.
$fullTable.=$this->pi_list_modeSelector($items);
// Adds the whole list table
$fullTable.=$this->pi_list_makelist($res);
// Adds the search box:
$fullTable.=$this->pi_list_searchBox();
// Adds the result browser:
$fullTable.=$this->pi_list_browseresults();
// Returns the content from the plugin.
return $fullTable;
}
}
/**
* [Put your description here]
*/
function singleView($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
// This sets the title of the page for use in indexed search results:
if ($this->internal['currentRow']['title']) $GLOBALS['TSFE']->indexedDocTitle=$this->internal['currentRow']['title'];
$content='<div'.$this->pi_classParam('singleView').'>
<h2>Record "'.$this->internal['currentRow']['uid'].'" from table "'.$this->internal['currentTable'].'":</h2>
<table>
<tr>
<td nowrap="" valign="top" this-="">pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('testfeld1').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('testfeld1').'</p></td>
</tr>
<tr>
<td nowrap="" valign="top" this-="">pi_classParam('singleView-HCell').'><p>'.$this->getFieldHeader('verknuepfung').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('verknuepfung').'</p></td>
</tr>
<tr>
<td nowrapthis-="">pi_classParam('singleView-HCell').'><p>Last updated:</p></td>
<td valign="top"><p>'.date('d-m-Y H:i',$this->internal['currentRow']['tstamp']).'</p></td>
</tr>
<tr>
<td nowrapthis-="">pi_classParam('singleView-HCell').'><p>Created:</p></td>
<td valign="top"><p>'.date('d-m-Y H:i',$this->internal['currentRow']['crdate']).'</p></td>
</tr>
</table>
<p>'.$this->pi_list_linkSingle($this->pi_getLL('back','Back'),0).'</p></div>'.
$this->pi_getEditPanel();
return $content;
}
/**
* [Put your description here]
*/
function pi_list_row($c) {
$editPanel = $this->pi_getEditPanel();
if ($editPanel) $editPanel='<td>'.$editPanel.'</td>';
return '<tr'.($c%2 this-="">pi_classParam('listrow-odd') : '').'>
<td><p>'.$this->getFieldContent('uid').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('testfeld1').'</p></td>
<td valign="top"><p>'.$this->getFieldContent('verknuepfung').'</p></td>
</tr>';
}
/**
* [Put your description here]
*/
function pi_list_header() {
return '<tr'.$this->pi_classParam('listrow-header').'>
<td><p>'.$this->getFieldHeader_sortLink('uid').'</p></td>
<td><p>'.$this->getFieldHeader_sortLink('testfeld1').'</p></td>
<td nowrap=""><p>'.$this->getFieldHeader('verknuepfung').'</p></td>
</tr>';
}
/**
* [Put your description here]
*/
function getFieldContent($fN) {
switch($fN) {
case 'uid':
return $this->pi_list_linkSingle($this->internal['currentRow'][$fN],$this->internal['currentRow']['uid'],1); // The "1" means that the display of single items is CACHED! Set to zero to disable caching.
break;
default:
return $this->internal['currentRow'][$fN];
break;
case 'verknuepfung':
if(!count($this->verknuepfungCache)) {
$query = 'SELECT * FROM tx_test_test2 WHERE pid='.intval($GLOBALS["TSFE"]->id).
$this->cObj->enableFields('tx_test_test2');
$res = mysql(TYPO3_DB,$query);
while($row=mysql_fetch_assoc($res)) {
$this->verknuepfungCache[$row['uid']]=$row;
}
}
return htmlspecialchars($this->verknuepfungCache[$this->internal['currentRow']['verknuepfung']]['tab2_feld1']);
break;
}
}
/**
* [Put your description here]
*/
function getFieldHeader($fN) {
switch($fN) {
default:
return $this->pi_getLL('listFieldHeader_'.$fN,'['.$fN.']');
break;
}
}
/**
* [Put your description here]
*/
function getFieldHeader_sortLink($fN) {
return $this->pi_linkTP_keepPIvars($this->getFieldHeader($fN),array('sort'=>$fN.':'.($this->internal['descFlag']?0:1)));
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/test/pi1/class.tx_test_pi1.php']);
}
?>
Der geänderte Teil ist der
case 'verknuepfung':
if(!count($this->verknuepfungCache)) {
$query = 'SELECT * FROM tx_test_test2 WHERE pid='.intval($GLOBALS["TSFE"]->id).
$this->cObj->enableFields('tx_test_test2');
$res = mysql(TYPO3_DB,$query);
while($row=mysql_fetch_assoc($res)) {
$this->verknuepfungCache[$row['uid']]=$row;
}
}
return htmlspecialchars($this->verknuepfungCache[$this->internal['currentRow']['verknuepfung']]['tab2_feld1']);
break;
Habe ich dem Video (Part 6) von Kaspar entnommen.
Bekomme wenn ich das jetzt so habe folgende Fehlermeldung:
3 X
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /srv/www/htdocs/entwicklung/typo3conf/ext/test/pi1/class.tx_test_pi1.php on line 199
1x
Warning: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/entwicklung/typo3conf/ext/test/pi1/class.tx_test_pi1.php:199) in /srv/www/htdocs/entwicklung/tslib/class.tslib_fe.php on line 2612
Angezeigt wird in dem Feld verknuepfung natürlich nichts, der Rest schon.
Gruß
Thorsten