You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TYPO3 6.2.4/Extbase扩展fe_users时出现属性未找到错误

解决TYPO3中扩展fe_users表时的「属性未找到」错误

看起来你在继承FrontendUser扩展fe_users表时踩了Extbase常见的配置坑,我帮你梳理几个最可能的原因和解决步骤:


1. 补全Persistence的TypoScript映射配置

你提到的TypoScript配置大概率没写完整,Extbase需要明确知道你的Laeufer模型对应哪个数据库表,以及是否使用recordType区分用户类型。完整的配置应该像这样:

plugin.tx_lhsponsorenlauf {
    persistence {
        classes {
            Vendor\LhSponsorenlauf\Domain\Model\Laeufer {
                mapping {
                    tableName = fe_users
                    # 如果你需要区分普通fe_users和你的Laeufer用户,加上这行
                    recordType = Vendor\LhSponsorenlauf\Domain\Model\Laeufer
                }
            }
        }
    }
}

别忘了把这段配置放到扩展的ext_typoscript_setup.txt里,并且在后端激活扩展的静态模板。

2. 确保模型属性的定义规范

你的Laeufer模型里新增的字段,必须遵循Extbase的规则:

  • 属性用protected修饰
  • 每个属性要有对应的getter和setter方法
  • 加上正确的注释(虽然不是强制,但能避免很多隐式问题)

举个例子,如果你新增了sponsorAmount字段,模型代码应该是:

class Laeufer extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
    /**
     * @var float
     */
    protected $sponsorAmount = 0.0;

    /**
     * @return float
     */
    public function getSponsorAmount() {
        return $this->sponsorAmount;
    }

    /**
     * @param float $sponsorAmount
     */
    public function setSponsorAmount(float $sponsorAmount) {
        $this->sponsorAmount = $sponsorAmount;
    }
}

3. 检查数据库字段与TCA配置

  • 数据库字段:要确保fe_users表中已经添加了对应的字段,比如tx_lhsponsorenlauf_sponsor_amount(遵循扩展前缀+字段名的命名规范)。可以在ext_tables.sql里定义:
ALTER TABLE fe_users ADD COLUMN tx_lhsponsorenlauf_sponsor_amount decimal(10,2) DEFAULT '0.00' NOT NULL;

然后去TYPO3后端执行「数据库分析」,确认字段已创建。

  • TCA配置:需要在Configuration/TCA/Overrides/fe_users.php里配置字段的显示和映射,比如:
<?php
defined('TYPO3_MODE') || die();

// 添加字段到fe_users的TCA
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'fe_users',
    [
        'tx_lhsponsorenlauf_sponsor_amount' => [
            'exclude' => 1,
            'label' => 'LLL:EXT:lh_sponsorenlauf/Resources/Private/Language/locallang_db.xlf:fe_users.sponsor_amount',
            'config' => [
                'type' => 'input',
                'size' => 10,
                'eval' => 'double2',
            ],
        ],
    ]
);

// 将字段添加到用户编辑页面的标签页中
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
    'fe_users',
    '--div--;LLL:EXT:lh_sponsorenlauf/Resources/Private/Language/locallang_db.xlf:tab.sponsorship, tx_lhsponsorenlauf_sponsor_amount',
    '',
    'after:email'
);

4. 强制清除所有缓存

TYPO3的缓存经常是这类问题的元凶,尤其是Extbase的类映射缓存。一定要去后端点击「清除所有缓存」(包括配置缓存、类缓存和页面缓存),确保新的模型配置被加载。

5. 控制器与视图的细节检查

你的newAction里如果没有初始化$newLaeufer,可能会导致视图里访问属性时报错。可以加个初始化逻辑:

public function newAction(\Vendor\LhSponsorenlauf\Domain\Model\Laeufer $newLaeufer = NULL) {
    if ($newLaeufer === NULL) {
        $newLaeufer = $this->objectManager->get(\Vendor\LhSponsorenlauf\Domain\Model\Laeufer::class);
    }
    $this->view->assign('laeufer', $newLaeufer);
}

同时检查Fluid模板里的属性拼写是否正确,比如{laeufer.sponsorAmount}不要写成字段名tx_lhsponsorenlauf_sponsor_amount。


内容的提问来源于stack exchange,提问作者Ralf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:35:07