Zum Inhalt springen

Listview und Detailview mit Ajax

Erstellt am 1. Februar 2011 · 10 Antworten · letzte Antwort am 10. Februar 2011

Tags: JavaScript & AJAX, Frage

Fiberman ·

Hallo,

ich habe eine Extension geschrieben, und würde gerne die Ausgabe der Links, die in der Listview vorhanden sind mittels Ajax ausgeben. (ohne reload). Kann mir jemand dazu bitte Tutorials oder Hilfestellung geben.

Vielen Dank
Gruß Fiberman

Fiberman ·

ich hab mir das mal angesehen, aber weiss nicht genau wie ich das integrieren soll.
Kannst du mir da ein wenig unter die Arme greifen?

sobi555 ·
require_once(t3lib_extMgm::extPath('xajax') . 'class.tx_xajax.php');

...



       // Ajax an
    $this->xajax = t3lib_div::makeInstance('tx_xajax');
    $this->xajax->setCharEncoding("iso-8859-1" ) ;
    $this->xajax->bStatusMessages = 1;
    $this->xajax->bDebug = 0;
    $this->xajax->registerFunction(array(startANDfinish, &$this, startANDfinish));      
    $this->xajax->processRequests();
    if(!in_array($this->xajax->getJavascript("typo3conf/ext/xajax/" ) , $GLOBALS['TSFE']->additionalHeaderData)) {
      $GLOBALS['TSFE']->additionalHeaderData[] = $this->xajax->getJavascript( "typo3conf/ext/xajax/ " ) ;
    }

startANDfinish ist deine php-Funktion, die du entsprechend füllen musst. Den Rest findest du im INternet! 😉

Fiberman ·

ok, jetzt bin ich schon einen Schritt weiter.

Muss ich jetzt meine class.tx_extension_pi1.php dort einbinden? Das reicht?

sobi555 ·

na probiers aus! 😉 - wenn du es 1:1 übernimmst, reicht es natürlich nicht aus. Ändern musst du es schon selber! 8-)

Fiberman ·

Bei meiner Extension ist die Ausgabe auf einem Frontendplugin.
Ich habe die Extension xajax installiert, dort gibt es aber keinen Ordner pi1?

Wo in welcher Datei muss ich den den Code unterbringen?

Ich glaube ich sehe den Wald vor lauter Bäumen nicht #angry#

Fiberman ·

Hallo,

erstmal Danke für Deine Geduld! Irgendwie komm ich nicht weiter und hänge fest. Egal was ich probiere. Langsam glaube ich es verträgt sich diese Extension nicht mit einer anderen oder es liegt an der T3 4.4.6er Version.

Schau bitte nochmal über meinen Code,

Gruß Fiberman

<?php

class tx_extension_pi1 extends tslib_pibase {
	var $prefixId      = 'tx_extension_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_extension_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey        = 'extension';	// The extension key.
	var $pi_checkCHash = true;
	var $template;
    var $id;
	 
	function main($content,$conf)    {
        $this->conf=$conf;
        $this->pi_setPiVarDefaults();
        $this->pi_loadLL();
        
       
        $this->id=$GLOBALS['TSFE']->id;
        $this->template=$this->cObj->fileResource('EXT:extension/template.html');
        $this->pi_initPIflexForm();
        
        /**
		* Instantiate the xajax object and configure it
		*/
		// Include xaJax
		require_once (t3lib_extMgm::extPath('xajax') . 'class.tx_xajax.php');
		// Make the instance
		$this->xajax = t3lib_div::makeInstance('tx_xajax');
		// nothing to set, we send to the same URI
		# $this->xajax->setRequestURI('xxx');
		// Decode form vars from utf8 ???
		$this->xajax->decodeUTF8InputOn();
		// Encode of the response to utf-8 ???
		$this->xajax->setCharEncoding('utf-8');
		// To prevent conflicts, prepend the extension prefix
		$this->xajax->setWrapperPrefix($this->prefixId);
		// Do you wnat messages in the status bar?
		$this->xajax->statusMessagesOn();
		// Turn only on during testing
		#$this->xajax->debugOn();
		// Register the names of the PHP functions you want to be able to call through xajax
		// $xajax->registerFunction(array('functionNameInJavascript', &$object, 'methodName'));
		$this->xajax->registerFunction(array('listView', &$this, 'listView'));
		// If this is an xajax request, call our registered function, send output and exit
		$this->xajax->processRequests();
		// Else create javascript and add it to the header output
		$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId] = $this->xajax->getJavascript(t3lib_extMgm::siteRelPath('xajax'));
		
		if($this->piVars['item']) {
            $content = $this->detailView();
        } else {
            $content = $this->listView();
        }
		return $this->pi_wrapInBaseClass($content);
    }

	
	function listView() {
        $subpart=$this->cObj->getSubpart($this->template,'###LISTVIEW###'); 
        $singlerow=$this->cObj->getSubpart($subpart,'###ROW###'); 
        
        $res=$GLOBALS['TYPO3_DB']->exec_SELECTquery(
        '*',   #select
        'tx_extension_haus', #from
        'hidden=0 and deleted=0 and pid='.$this->id,  #where
        $groupBy='',
        $orderBy='',
        $limit='');
        
        if($res) {
            $liste='';
            while($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                $markerArray['###HAUS###']=$this->pi_linkTP($row['haus'],array($this->prefixId.'[item]'=> $row['uid']));
                $liste .= $this->cObj->substituteMarkerArrayCached($singlerow,$markerArray);    
            }
            $subpartArray['###ROW###']=$liste;
        } else {
            return $this->pi_getLL('nodata');
        }
        return $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,$subpartArray,array());     
    }
	 
	 function detailView() {
        #unser Subpart
        $subpart=$this->cObj->getSubpart($this->template,'###DETAILVIEW###'); 
        #Datensatz holen
        $record=$this->pi_getRecord('tx_extension_haus',$this->piVars['item']);
        #Marker füllen
        $markerArray['###HAUS###']=$record['haus'];
        $markerArray['###ANREDE###']=$record['anrede'];
        $markerArray['###VORNAME###']=$record['vorname'];
        $markerArray['###NACHNAME###']=$record['nachname'];
        $markerArray['###STRASSE###']=$record['strasse'];
        $markerArray['###PLZ###']=$record['plz'];
        $markerArray['###ORT###']=$record['ort'];
        $markerArray['###TELEFON###']=$record['telefon'];
        $markerArray['###HANDY###']=$record['handy'];
        $markerArray['###SONSTIGES###']=$this->pi_RTEcssText($record['sonstiges']);
        $markerArray['###EMAIL###']=$this->cObj->typolink($record['email'],array(
            'parameter' => $record['email'],
            'extTarget' => '_blank',
        ));
        #backlink als einfachen Link ohne Parameter
        $markerArray['###BACKLINK###']=$this->pi_linkToPage($this->pi_getLL('back'),$this->id);
        return $this->cObj->substituteMarkerArrayCached($subpart,$markerArray,array(),array());     
           }
    
}  

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/extension/pi1/class.tx_extension_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/extension/pi1/class.tx_extension_pi1.php']);
}

?>
sobi555 ·
<?php
  require_once (t3lib_extMgm::extPath('xajax').'class.tx_xajax.php');
  class tx_extension_pi1 extends tslib_pibase {
  var $xajax;

Dann (soweit ich das sehe) mach der gesamte aufbau keinen Sinn. Du steuerst die beiden funktion (detail und list) über den PHP Code:

		if($this->piVars['item']) {
            $content = $this->detailView();
        } else {
            $content = $this->listView();
        }
		return $this->pi_wrapInBaseClass($content);
    }

an... warum? Du willst es doch eigentlich über AJAX steuern...??
Das heißt, du musst nicht die "list-function" mit ajax ansteurn (sprich das hier ist falsch

		$this->xajax->registerFunction(array('listView', &$this, 'listView'));

)
sondern die detail-funktion. Und du musst aus der listfunktion deine detail-funktion aufrufen. Sprich, wenn auf einen eintrag geklickt wird, musst die listfunktion den inhalt nachladen...

LG-Simon