[TYPO3-dev] TCA in loop doesn't work

Wolfgang Klinger wolfgang at stufenlos.net
Mon Jan 2 08:47:28 CET 2006


 Hi!

 On Sun, 01 Jan 2006, Christoph Koehler wrote the following:
> Now if I debug that and take al ook at type, it shows the right type when  
> $index = 0, but every single time afterwards, $type becomes null. I have  
> no idea why.
> 
> Here is the rest of my function:
> 
> function makeForm($fields = null) {
> 	$content = null;
> 	$fields = explode(',', $fields);
> 	$GLOBALS['TSFE'] -> includeTCA(1);
> 	$temp = $GLOBALS['TCA'];
> 
> 	for ($index = 0; $index < sizeof($fields); $index++) {
> 		$type = null;
> 		$type =  
> $GLOBALS['TCA']['fe_users']['columns'][$fields[$index]]['config']['type'];
> 		[snip]
> 	}
> 
> 	return $content;
> }

 Some hints to improve your code:

 (1)
 if you set $fields to "null" by default and then try to explode you'll
 get an error... test if $fields is an array before exploding it
----
if (is_array($fields)) {
....
}
----
 (2)
 use foreach to loop through an array (your array might have non-numerical
 indexes)
----
if (is_array($fields)) {
    foreach ($fields as $field) {
        $type = $GLOBALS['TCA']['fe_users']['columns'][$field]['config']['type'];
    }
}
----
 (3)
 setting variables to "null" is unnecessary
 (you don't have to declare variables in PHP, so why would you set it to
 "null" initially?)

 hope that helps...


 kind regards
 Wolfgang





More information about the TYPO3-dev mailing list