Fel*_*lix 3 php typo3 typo3-6.2.x
是否有任何posibillity从php文件访问控制器功能,该文件基于resource/public/php/file.php
我想要的是这个php文件是我使用它的特殊文件:
<img src="file.php"></img>
Run Code Online (Sandbox Code Playgroud)
我将禁用可读路径.所以这个php文件做了一些加密,需要连接到普通的控制器功能.
谢谢
是否有任何posibillity从php文件访问控制器功能,该文件基于resource/public/php/file.php
是的,这是可能的,但是你也需要bootstrapTYPO3核心.或者,如果它是一个static和public方法比你可以直接调用它.
但在你的情况下,这似乎不是正确的方法.
假设你正在研究某种验证码的东西,你应该考虑自己page type的渲染dynamic images.这是一个有效的例子:
TypoScript设置
在TypoScript中,我们正在注册我们自己page typ并指出它们extension,controller并且action:
DynamicCaptchaImage = PAGE
DynamicCaptchaImage {
typeNum = 1234
10 = USER_INT
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Pi1
extensionName = MyExtName
vendorName = MyCompanyName
controller = MyExtbaseController
action = renderCaptchaImage
# view =< plugin.tx_myextname.view // you provide the view yourself
# persistence =< plugin.tx_myextname.persistence // in case you need a repository you should uncomment it
settings =< plugin.tx_myextname.settings
}
config {
disableAllHeaderCode = 1
additionalHeaders = Content-Type: image/png
xhtml_cleaning = 0
admPanel = 0
debug = 0
}
}
Run Code Online (Sandbox Code Playgroud)
另请参阅:注册基于typeNum的自定义Controller访问
调节器
以下是您controller和action应该如何看待的示例:
<?php
namespace MyCompanyName\MyExtName\Controller;
/**
* MyExtbaseController
*/
class MyExtbaseController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* Render Captcha Image Action
*
* @return void
*/
public function renderCaptchaImageAction() {
// Send some headers
header('Content-Type: image/png');
// < do your magic stuff here >
// Breaks the script because we've sent already some headers and want
// to prevent that TYPO3 is adding another stuff (eg. for debugging purposes)
// that can break the image from loading.
// return FALSE; does not stop doing that!
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
另请参阅:Extbase wiki
访问控制器
现在我们page type通过调用page typeTypoScript设置中的给定来配置我们允许访问控制器的自定义.
例如.http://www.example.com?type=1234指出到renderCaptchaImageAction()的MyExtbaseController.
流体
在Fluid中,您可以链接到page type您配置的:
<img src="{f:link.page(pageType: 1234)}" />
Run Code Online (Sandbox Code Playgroud)
另见:Fluid wiki
Realurl
如果您正在使用扩展程序realurl,则可以通过以下方式更改?type=1234为captcha.png:
// [...]
'fileName' => array(
'index' => array(
'captcha.png' => array(
'keyValues' => array(
'type' => 1234,
),
),
),
),
// [...]
Run Code Online (Sandbox Code Playgroud)
另请参见:Realurl wiki