userFunc has no effect in TYPO3 4.5

714 views Asked by At

I have been struggling with USER and USER_INT for quite a while now. At first I thought my problem was related to TemplaVoila, but in the end I reverted to a clean installation of TYPO3 version 4.5.40, and the problem persists.

To test it I have made a new installation of version 4.5.40.
My template setup looks like this:

includeLibs.beechgroveTest = fileadmin/php/test.php

page = PAGE
page {
  10 = USER
  10 {
    userFunc = getBeechgroveTest
  }
}

In fileadmin/php/test.php I have this code:

<?php

function getBeechgroveTest($content, $conf) {
  return "func";
}

echo "Load: ";

?>

In the page module I have added a shortcut to a standard page. the standard page has no content elements.
Apart from that no changes have been made since the install.

When I load the website I see the text 'Load: '.
If I reload the website then the text disappears.
If I change USER to USER_INT the text remains, when I reload the website.
This tells me that USER and USER_INT is being recognized, but userFunc seems to be ignored.

I made the same test with a clean install of version 6.2.13.
But here I get the text 'Load: func'.
And when I reload it changes to 'func'. If I use USER_INT the text 'Load: func' remains, when I reload.

In other words with version 6.2 it works as expected, but not in version 4.5. All the information I have been able to find, indicates that it should work in 4.5, so what am I missing?
Is there some configuration that needs to be done in order to enable userFunc in 4.5?

2

There are 2 answers

1
pgampe On

This calls either a PHP function or a method in a class. This is very useful if you want to incorporate your own data processing or content. http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/UserAndUserInt/Index.html

That means you have to put your function inside a class, make sure that this class is autoload-able (naming convention) and use the form class->method to register your methods.

Please keep in mind that the possible class names are restricted.

0
Henrik Bøgelund On

The solution was found at this link: http://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Functionname/Index.html

It states that the function name must start with 'user_'.
So the following code works as intended:

Template:

includeLibs.beechgroveTest = fileadmin/php/test.php

page = PAGE
page {
  10 = USER
  10 {
     userFunc = user_getBeechgroveTest
  }
}

php:

<?php

function user_getBeechgroveTest($content, $conf) {
  return "func";
}

echo "Load: ";

?>

Apparently this restriction has been lifted in version 6.2.