TYPO3 为 feuser 添加图片上传字段 [英] TYPO3 add image upload field to feuser
问题描述
TYPO3 版本 7.6.18.我需要用新的字段来扩展 fe_user 来上传图片吗?怎么做?我需要将此字段添加到前端和后端
ext_tables.php
创建表 fe_users (backgroundimage int(11) 无符号 NOT NULL 默认值 '0');
用户.php
class User extends \In2code\Femanager\Domain\Model\User{/*** @var 字符串*/受保护的 $backgroundimage = null;/*** 返回背景值** @return 字符串* @api*/公共函数 getBackgroundimage(){返回 $this->backgroundimage;}/*** 设置图片背景图片** @param $backgroundimage*/公共函数 setBackgroundimage(\TYPO3\CMS\Extbase\Domain\Model\FileReference$背景图片){$this->backgroundimage = $backgroundimage;}/*** __构造*/公共函数 __construct(){//不要删除下一行:它会破坏功能$this->initStorageObjects();}/*** 初始化所有 ObjectStorage 属性* 不要修改这个方法!*它将在扩展构建器中的每次保存时重写* 你可以修改这个类的构造函数** @return 无效*/受保护的函数 initStorageObjects(){}}
setup.txt
config.tx_extbase{坚持{类{In2code\Femanager\Domain\Model\User {子类{0 = Fhk\Feusersplus\域\模型\用户}}Fhk\Feusersplus\Domain\Model\User {映射{表名 = fe_users记录类型 = 0}}}}对象{In2code\Femanager\Controller\NewController.className = Fhk\Feusersplus\Controller\NewControllerIn2code\Femanager\Controller\EditController.className = Fhk\Feusersplus\Controller\EditControllerIn2code\Femanager\Controller\UserController.className = Fhk\Feusersplus\Controller\UserController#Kenziffer\KeQuestionnaire\Domain\Repository\ResultRepository.className = Fhk\Feusersplus\Domain\Repository\ResultRepository}}
有我的文件.怎么了 ?
这是我的 Backgroundimage.html
{namespace femanager=Istar\Fefiles\ViewHelpers}<f:render section="default" arguments="{_all}"/><f:section name="默认"><div class="femanager_fieldset femanager_backgroundimage control-group"><label for="femanager_field_backgroundimage" class="control-label"><f:translate key="tx_feusersplus_domain_model_user.backgroundimage" default="个人资料背景图片"/>标签><femanager:form.upload property="backgroundimage" ><f:if condition="{resource}"><f:image image="{resource}" alt="" width="50"/></f:if></femanager:form.upload><br/>
</f:section>
我的设置方法
公共函数setBackgroundimage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $backgroundimage){$this->backgroundimage = $backgroundimage;}
好吗?我仍然有同样的错误((
现在我有以下错误:
在属性路径backgroundimage"上映射属性时出现异常:身份属性2.jpg"没有 UID.
按照以下步骤扩展 FE 用户.
更新的答案
只需更新您的模型文件 User.php 如下
/*** @var \TYPO3\CMS\Extbase\Domain\Model\FileReference*/受保护的 $backgroundimage = null;
创建ext_tables.sql
创建表 fe_users (imsge int(11) 无符号 NOT NULL 默认值 '0',);
为 ext_tables.php 文件中的图像字段添加 TCA 配置
$tempColumns = 数组 ('图像' =>大批('排除' =>1、'标签' =>'添加图像标签','配置' =>\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('图片',大批('外观' =>大批('createNewRelationLinkTitle' =>'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'),'foreign_types' =>大批('0' =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板'),\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板'),\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板'),\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板'),\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板'),\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION =>大批('showitem' =>'--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--调色板--;;文件调色板')),'maxitems' =>1),$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),'pdf、doc、docx'),),);\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns("fe_users",$tempColumns,1);\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes("fe_users","image");
映射图像字段与 fe_user 表.ext_typoscript_setup.txt
config.tx_extbase{坚持{类{TYPO3\CMS\Extbase\Domain\Model\FrontendUser {子类{Tx_Extendfeuser_User = VendorName\ExtensionName\Domain\Model\User}}供应商名称\扩展名\域\型号\用户{映射{表名 = fe_users记录类型 = 0}}}}}
创建模型字段 User.php
image;}/*** 设置图像** @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image 图像** @return 无效*/公共函数 setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image){$this->image = $image;}}
此外,如果您想使用 FE Manager 扩展扩展 Fe 用户,请点击链接 扩展 Fe 用户
TYPO3 version 7.6.18. I need to extend fe_user with new field for uploading image ? How to do it? I need add this field to front-end and back-end
ext_tables.php
CREATE TABLE fe_users (
backgroundimage int(11) unsigned NOT NULL default '0'
);
User.php
class User extends \In2code\Femanager\Domain\Model\User
{
/**
* @var string
*/
protected $backgroundimage = null;
/**
* Returns the background value
*
* @return string
* @api
*/
public function getBackgroundimage()
{
return $this->backgroundimage;
}
/**
* Sets the image backgroundimage
*
* @param $backgroundimage
*/
public function setBackgroundimage(\TYPO3\CMS\Extbase\Domain\Model\FileReference
$backgroundimage)
{
$this->backgroundimage = $backgroundimage;
}
/**
* __construct
*/
public function __construct()
{
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* @return void
*/
protected function initStorageObjects()
{
}
}
setup.txt
config.tx_extbase{
persistence{
classes{
In2code\Femanager\Domain\Model\User {
subclasses {
0 = Fhk\Feusersplus\Domain\Model\User
}
}
Fhk\Feusersplus\Domain\Model\User {
mapping {
tableName = fe_users
recordType = 0
}
}
}
}
objects {
In2code\Femanager\Controller\NewController.className = Fhk\Feusersplus\Controller\NewController
In2code\Femanager\Controller\EditController.className = Fhk\Feusersplus\Controller\EditController
In2code\Femanager\Controller\UserController.className = Fhk\Feusersplus\Controller\UserController
#Kennziffer\KeQuestionnaire\Domain\Repository\ResultRepository.className = Fhk\Feusersplus\Domain\Repository\ResultRepository
}
}
There are my files. What is wrong ?
it is my Backgroundimage.html
{namespace femanager=Istar\Fefiles\ViewHelpers}
<f:render section="default" arguments="{_all}" />
<f:section name="default">
<div class="femanager_fieldset femanager_backgroundimage control-group">
<label for="femanager_field_backgroundimage" class="control-label">
<f:translate key="tx_feusersplus_domain_model_user.backgroundimage" default="Profile background image"/>
</label>
<femanager:form.upload property="backgroundimage" >
<f:if condition="{resource}">
<f:image image="{resource}" alt="" width="50"/>
</f:if>
</femanager:form.upload><br />
</div>
</div>
</f:section>
my set method
public function setBackgroundimage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $backgroundimage)
{
$this->backgroundimage = $backgroundimage;
}
All right? I still have the same error((
Now I have follow error:
Exception while property mapping at property path "backgroundimage": The identity property "2.jpg" is no UID.
Follow below steps for Extend FE USERS.
Updated answers
Just Update your model file User.php Like below
/**
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $backgroundimage = null;
Create ext_tables.sql
CREATE TABLE fe_users (
imsge int(11) unsigned NOT NULL default '0',
);
Add TCA Configuration for image fields in ext_tables.php file
$tempColumns = Array (
'image' => array(
'exclude' => 1,
'label' => 'Add image Lables',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
'foreign_types' => array(
'0' => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
)
),
'maxitems' => 1
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
'pdf,doc,docx'
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns("fe_users",$tempColumns,1);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes("fe_users","image");
Mapping image fields with fe_user tables. ext_typoscript_setup.txt
config.tx_extbase{
persistence{
classes{
TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
subclasses {
Tx_Extendfeuser_User = VendorName\ExtensionName\Domain\Model\User
}
}
VendorName\ExtensionName\Domain\Model\User {
mapping {
tableName = fe_users
recordType = 0
}
}
}
}
}
Create Model fiel User.php
<?php
namespace VendorName\ExtensionName\Domain\Model;
/***************************************************************
*
* Copyright notice
*
* (c) 2015
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Users
*/
class User extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* image
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $image = null;
/**
* Returns the image
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage()
{
return $this->image;
}
/**
* Sets the image
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image image
*
* @return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image)
{
$this->image = $image;
}
}
Also If you want extend Fe user With FE Manager extension then follow the link Extend Fe Users
这篇关于TYPO3 为 feuser 添加图片上传字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!