[TYPO3-UG Dutch] php vraag

Anthony Donker / Inconel BV anthony at inconel.nl
Mon Nov 19 16:22:32 CET 2007


Hoi Frans en Leen,

Persoonlijk zou ik dan de HTML-code ophalen via een template en
vervangen, bijv:

/* laad de filetemplate */
$this->templateFile = 'template.tmpl';
$this->templateCode = $this->cObj->fileResource($this->templateFile);

$query =
$GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_companyoffers_category','
pid >0');
$optionsRow = '';
while($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)){
	 $optMarker['###OPTIONID###'] = $res['uid'];
	 $optMarker['###OPTIONDESC###'] = $res['title'];
       $optionsRow .= $this->getTemplate('OPTIONROW',$optMarker);
}

... Waarbij getTemplate() een functie is die we hebben geschreven en ik
altijd include (we zijn tenslotte luie programmeurs)
In in de pi plaatsen onderaan (wel binnen de classe maar buiten de
function main()):

function getTemplate($code, $markerArray=''){
	$t[$code] = $this->cObj->getSubpart($this->templateCode,
"###".$code."###");
	return $this->cObj->substituteMarkerArrayCached($t[$code],
$markerArray, array(), array());
	}	


-- de template 'template.tmpl' --
<!-- ###OPTIONROW### start -->
<option value="###OPTIONID###">###OPTIONDESC###</option> 
<!-- ###OPTIONROW### end -->

...ik hoop dat mijn verhaal zo een beetje duidelijk genoeg is anders kan
ik het wel uitschrijven.
Op deze manier houd je de HTML-code buiten de plugin en is makkelijker
te stylen voor anderen en jezelf.

Groetjes,

Anthony


-----Oorspronkelijk bericht-----
Van: typo3-ug-dutch-bounces at lists.netfielders.de
[mailto:typo3-ug-dutch-bounces at lists.netfielders.de] Namens Frans Saris
Verzonden: maandag 19 november 2007 8:48
Aan: TYPO3 Usergroup Dutch
Onderwerp: Re: [TYPO3-UG Dutch] php vraag

Hoi Leen,

zelf zou ik het als volgt doen:

$query =
$GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_companyoffers_category','
pid >0');
while($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)){
       $options[$res['uid']] = '<option value="'.$res['uid'].'">
'.$res['title'].'</option>'; } return implode('',$options);

of als dit alles is wat de functie moet doen:

$query =
$GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_companyoffers_category','
pid >0');
$options = '';
while($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)){
       $options .= '<option value="'.$res['uid'].'">
'.$res['title'].'</option>'; } return $options;



gr. Frans

Op 18-11-07 heeft Leen Strijk<leenstrijk at tomaatnet.nl> het volgende
geschreven:
> Leen Strijk schreef:
>
> Ik heb nu wel een oplossing maar ik vraag me af dit niet beter kan.
> Minder code??
> betere php functie??
> api functie??
>
> Dit is mijn oplossing:
> $query =
>
$GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_companyoffers_category','
> pid >0');
> while($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)){
>         $n = $res['uid'];
>         $row[$n]= '<option value="'.$res['uid'].'"> 
> '.$res['title'].'</option>'; $options= $options.$row[$n]; } return 
> $options;
>
> Graag de mening van een extensiebouwer
>
> Gr Leen
>
>
> > Hallo,
> >
> > Ik wil in een fe formulier die ik zelf aan het maken ben een 
> > selectbox maken die de waardes uit de database haalt.
> >
> > met:
> > $query = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','
> > tx_companyoffers_category', 'pid >0');
> >
> > while($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)){
> > echo $res['title'];
> > }
> >
> > Krijg ik ze wel getoond maar de uiteindelijke uitvoer moet een 
> > string worden.
> >
> > Dus ik moet uiteindelijk return $content; hebben met als uitvoer:
> > <option value="id">title1</option>
> > <option value="id">title2</option>
> > <option value="id">title3</option>
> > <option value="id">title4</option>
> >
> > Kan iemand mij op weg helpen?
> >
>
> _______________________________________________
> TYPO3-UG-dutch mailing list
> TYPO3-UG-dutch at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-ug-dutch
>
_______________________________________________
TYPO3-UG-dutch mailing list
TYPO3-UG-dutch at lists.netfielders.de
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-ug-dutch




More information about the TYPO3-UG-dutch mailing list