'typoscript call php function and print result
I want to call a simple PHP script with typoscript to print the results of it.
I tried this,
lib.doSomething = USER
lib.doSomething {
userFunc = fileadmin/pcoShowBlog.inc.php
}
page.20.marks.kumulierterInhalt < lib.doSomething
What is wrong in this case?
Update
also tried this:
lib.obj = USER
lib.obj.includeLibs = fileadmin/pcoShowBlog.inc.php
lib.obj.userFunc = Blog->showBlog
page.20.marks.kumulierterInhalt < lib.obj
and this:
page.10 = USER_INT
page.10 {
userFunc = In2code\MyUserFuncs\Blog->showBlog
}
page.20.marks.kumulierterInhalt = page.10.userFunc
Solution 1:[1]
You should not have any PHP files in fileadmin (security)!
Use an own extension and give the class and method name to the userFunc.
lib.doSomething.userFunc = Vendor\ExtensionName\UserFunc\ShowBlog->methodName
Solution 2:[2]
I work on TYPO3 10.4
I wanted to run function from my controller before frontend login, so I created my plugin and put it above felogin plugin.
For call function from my controller I use typoscipt like this:
lib.doSomething = USER
lib.doSomething {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = extName
vendorName = vendor
pluginName = plugin
}
In template I just put
<f:cObject typoscriptObjectPath="lib.doSomething"/>
Problem can appears with more then one function in controller, because switchableControllerActions is deprecated, I suggest this solution: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.3/Deprecation-89463-SwitchableControllerActions.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Thomas Löffler |
Solution 2 |