gpt4 book ai didi

php - 公共(public)文件夹访问 Controller 功能中的 typo3 php 文件

转载 作者:可可西里 更新时间:2023-11-01 00:19:43 25 4
gpt4 key购买 nike

是否可以从基于 resource/public/php/file.php 的 php 文件访问 Controller 函数

我想要的是这个 php 文件是我用它的特殊文件:

<img src="file.php"></img> 

我将禁用可读路径。所以这个 php 文件做了一些加密并且需要连接到一个普通的 Controller 函数。

谢谢

最佳答案

is there any posibillity to access a controller function from a php file that is based in resource/public/php/file.php

是的,这是可能的,但因此您还需要bootstrap TYPO3 内核。或者,如果它是一个 staticpublic 方法,那么您可以直接调用它。

但这似乎不是您的情况的正确方法。

假设您正在处理某种验证码问题,您应该考虑使用自己的页面类型 来呈现动态图像。这是一个工作示例:

TypoScript 设置

在 TypoScript 中,我们正在注册我们自己的 page typ 并将其指向我们的 extensioncontrolleraction:

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
}
}

另请参阅:Registering a custom typeNum-based Controller access

Controller

这是您的controlleraction 的示例:

<?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;
}

}

另请参阅:Extbase wiki

访问 Controller

现在我们已经配置了自定义页面类型,我们可以通过调用 TypoScript 设置中给出的页面类型来访问 Controller 。

例如。 http://www.example.com?type=1234指出 MyExtbaseController 中的 renderCaptchaImageAction()

流体

在 Fluid 中,您可以链接到您配置的页面类型:

<img src="{f:link.page(pageType: 1234)}" />

另请参阅:Fluid wiki

真实网址

如果您使用的是扩展程序 realurl,您可以通过以下方式将 ?type=1234 更改为 captcha.png:

// [...]
'fileName' => array(
'index' => array(
'captcha.png' => array(
'keyValues' => array(
'type' => 1234,
),
),
),
),
// [...]

另请参阅:Realurl wiki

关于php - 公共(public)文件夹访问 Controller 功能中的 typo3 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32717177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com