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

Christoph christoph.koehler at gmail.com
Mon Jan 2 17:56:22 CET 2006


On Mon, 02 Jan 2006 01:47:28 -0600, Wolfgang Klinger  
<wolfgang at stufenlos.net> wrote:

>
>  Hi!

Hello!


>
>  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)) {
> ....
> }
> ----

Yeah, this is just a leftover from the earlier function. It is only called  
once and that is to test it, I will remove that part later. It will also  
be a comma separated list, too, so it explodes into an array.



>  (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'];
>     }
> }
> ----

I did not know that! Thank you very much! No more  
$array[$arrayKeys[$index]] and array_keys() for me!


>  (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?)

I just did that because I thought it might make a difference. Turns out it  
doesn't.
This really seems like a bug to me, because the loop works, the $fields  
value is correct, but it just won't return the type. If I put a $temp var  
in there that gives me the TCA, $temp = $GLOBALS['TCA'], it give me an  
error when I try to open it in the debug view. Even echoing the $type only  
works once, so it can't be my debugger or IDE, either. Very odd.

Thanks for the help, I will make those changes now and see if they make a  
difference.

>
>  hope that helps...
>
>
>  kind regards
>  Wolfgang
>

Christoph




More information about the TYPO3-dev mailing list