TYPO3将图像上传字段添加到feuser

时间:2017-05-16 10:57:35

标签: typo3

TYPO3版本7.6.18。我需要使用新字段扩展fe_user以上传图像吗?怎么做?我需要将此字段添加到前端和后端

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

有我的档案。怎么了 ?

这是我的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>

我的设定方法

public function setBackgroundimage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $backgroundimage)
{
    $this->backgroundimage = $backgroundimage;
}
好的,好吗?我仍然有同样的错误((

现在我有以下错误:

属性路径中的属性映射异常&#34; backgroundimage&#34;:标识属性&#34; 2.jpg&#34;不是UID。

2 个答案:

答案 0 :(得分:1)

按照以下步骤扩展FE用户。

更新了答案

只需更新您的模型文件User.php,如下所示

/**
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $backgroundimage = null;

创建 ext_tables.sql

CREATE TABLE fe_users (
    imsge int(11) unsigned NOT NULL default '0',
);

ext_tables.php 文件

中的图片字段添加TCA配置
$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");
使用fe_user表

映射图像字段。的 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
                }
            }            
        }
    }
}

创建模型领域 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;
    }

}

此外,如果您希望使用FE Manager扩展程序扩展Fe用户,请点击链接Extend Fe Users

答案 1 :(得分:1)

请尝试使用此User.php

这样的模型
config.tx_extbase{
    persistence{
        classes{
            In2code\Femanager\Domain\Model\User {
                subclasses {
                    0 = vendorname\extname\Domain\Model\User
                }
            }
            vendorname\extname\Domain\Model\User {
                mapping {
                    tableName = fe_users
                    recordType = 0
                }
            }
        }
    }
}

您的 ext_typoscript_setup.txt 是这样的:

imshow