Php Type3(带extbase)流体:显示带绝对路径的图像src
对于XML导出,我需要输出2个图像的绝对路径。Image1位于/typo3conf/ext/app/Resources/Public/Images/Image1.png中 Image2位于/uploads/tx_extensionname/Image2.png中 就我的一生而言,我无法找到一种方法来获得图像的绝对路径。我尝试的是:Php Type3(带extbase)流体:显示带绝对路径的图像src,php,typo3,fluid,extbase,Php,Typo3,Fluid,Extbase,对于XML导出,我需要输出2个图像的绝对路径。Image1位于/typo3conf/ext/app/Resources/Public/Images/Image1.png中 Image2位于/uploads/tx_extensionname/Image2.png中 就我的一生而言,我无法找到一种方法来获得图像的绝对路径。我尝试的是: <f:uri.image absolute="1" src="EXT:app/Resources/Public/Images/image1.png"/>
<f:uri.image absolute="1" src="EXT:app/Resources/Public/Images/image1.png"/>
我还尝试了f:uri.resource,它适用于image1,但当然不适用于image2,因为没有extensionName
有什么提示吗 f:uri.imageview助手的
absolute
参数最近才在TYPO3 7.6.0中添加。见:
功能:#64286-在uri.image和image viewHelper中添加了绝对url选项
ImageViewhelper和Uri/ImageViewhelper获得了一个新选项absolute。使用此选项,您可以强制ViewHelper输出绝对url
我建议升级到TYPO3 7.6
如果出于任何原因,您不可能这样做,那么可以扩展f:uri.image
view助手。下面的代码未经测试,但应适用于6.2 LTS(我从7.6中的TYPO3\CMS\Extbase\Service\ImageService
中借用了部分代码):
f:uri.image
view助手的absolute
参数最近才在TYPO3 7.6.0中添加。见:
功能:#64286-在uri.image和image viewHelper中添加了绝对url选项
ImageViewhelper和Uri/ImageViewhelper获得了一个新选项absolute。使用此选项,您可以强制ViewHelper输出绝对url
我建议升级到TYPO3 7.6
如果出于任何原因,您不可能这样做,那么可以扩展f:uri.image
view助手。下面的代码未经测试,但应适用于6.2 LTS(我从7.6中的TYPO3\CMS\Extbase\Service\ImageService
中借用了部分代码):
好的,非常感谢!不幸的是,更新现在不是一个选项,但我将实现您对f:uri的扩展。image@Chi,只是出于好奇,这个解决方案对你有用吗?在我的回答中有什么我可以/应该改进的吗?我实际上尝试了你的解决方案-但在我的例子中,我未能使viewhelper在Typo3 6.2中工作。-它甚至不会加载(参数“绝对”未注册。)好的,非常感谢!不幸的是,更新现在不是一个选项,但我将实现您对f:uri的扩展。image@Chi,只是出于好奇,这个解决方案对你有用吗?在我的回答中有什么我可以/应该改进的吗?我实际上尝试了你的解决方案-但在我的例子中,我未能使viewhelper在Typo3 6.2中工作。-它甚至不会加载(参数“绝对”未注册。)
Argument "absolute" was not registered.
namespace Vendor\ExtensionKey\ViewHelpers\Uri;
use TYPO3\CMS\Fluid\ViewHelpers\Uri\ImageViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ImageViewHelper extends ImageViewHelper
{
public function render(
$src = null,
$image = null,
$width = null,
$height = null,
$minWidth = null,
$minHeight = null,
$maxWidth = null,
$maxHeight = null,
$treatIdAsReference = false,
$absolute = false
) {
$uri = parent::render($src, $image, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight, $treatIdAsReference);
if ($absolute) {
$uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
$uri = GeneralUtility::locationHeaderUrl($uriPrefix . $uri);
}
return $uri;
}
}