简体   繁体   English

TYPO3:扩展模型并映射到现有表

[英]TYPO3: Extend model and map to existing table

I need to create a custom FE user with some custom fields. 我需要使用一些自定义字段创建一个自定义FE用户。 Also, it needs to be assignable through the frontend to different user groups. 另外,还需要通过前端将其分配给不同的用户组。

You can find my first approach here . 您可以在这里找到我的第一种方法。 Didn't work out that well. 效果不好。

Second approach was to create another extension and follow the guide which is shown here . 第二种方法是创建另一个扩展,并按照此处显示的指南进行操作。

First thing I did was to add \\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser into the Extend existing model class-field for my CustomFEU-model. 我所做的第一件事是将\\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser\\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser的扩展现有模型类字段中。 Then I created another model which I named FEgroup and I mapped it to the table fe_groups . 然后,我创建了另一个名为FEgroup的模型,并将其映射到表fe_groups After that, I connected an n:m relation to the CustomFEU. 之后,我将n:m关系连接到CustomFEU。

When I try to create a new CustomFEU with the new action, it returns a white empty page after submitting the form and no user is being added. 当我尝试使用new操作创建新的CustomFEU时,提交表单后它将返回空白页面,并且未添加任何用户。

The only strange thing I found was that the /Classes/Domain/Repository/ folder is empty. 我发现的唯一奇怪的事情是/Classes/Domain/Repository/文件夹为空。

TYPO3 7.6.8 TYPO3 7.6.8

Although I didn't edit the files yet, here they are: 尽管我还没有编辑文件,但它们是:
Model / Controller / Setup 型号 / 控制器 / 设置

Did anyone encounter similar problems? 有没有人遇到类似的问题?

First you need to create the repositories that handle the new user and usergroup models. 首先,您需要创建用于处理新用户和用户组模型的存储库。

Second you try to save the user with $this->customFEURepository->add($newCustomFEU); 其次,您尝试使用$this->customFEURepository->add($newCustomFEU);保存用户$this->customFEURepository->add($newCustomFEU); and the variable customFEURepository does not exist. 并且变量customFEURepository不存在。 It would be the best to inject it, it has to be the repository that you should create first. 最好注入它,它必须是您应该首先创建的存储库。 You can inject it like that: 您可以像这样注入它:

/**
 * CustomFEUController
 */
class CustomFEUController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{

    /**
     * @var \Vendor\Feregistration\Repository\CustomFEURepository
     * @inject
     */
    protected $customFEURepository;

// other code ...
}

Don't forget to clear the system cache after adding inject annotations, otherwise it wont work. 添加注入注释后,不要忘记清除系统缓存,否则它将无法正常工作。

Last but not least i can't see the mapping to the database table for your model. 最后但并非最不重要的一点是,我看不到模型的数据库表映射。 You need to add it to your TypoScript (setup.txt) 您需要将其添加到您的TypoScript(setup.txt)中

config.tx_extbase.persistence.classes {

    Vendor\Feregistration\Domain\Model\CustomFEU {
        mapping {
            recordType = 0
            tableName = fe_users
        }
    }

    Vendor\Feregistration\Domain\Model\FEGroups {
        mapping {
            recordType = 0
            tableName = fe_groups
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM