gpt4 book ai didi

TYPO3 - TCA - change the value of one field when another changes(TYPO3-TCA-当一个字段的值更改时,更改另一个字段的值)

转载 作者:bug小助手 更新时间:2023-10-24 18:33:37 24 4
gpt4 key购买 nike



I have TYPO3 11.5.26.

I have a custom entity.

I generated a TCA configuration.

我的TYPO3是11.5.26。我有一个自定义实体。我生成了TCA配置。


I need to change the value of a field on certain conditions of another value field.

我需要在某个条件下更改另一个值字段的值。


Example:

If "deadline field date" <= today then "State field value" = "open" else "closed"

例如:如果“Deadline field Date”<=TODAY,则“State”字段值=“OPEN”,否则“CLOSED”


How can I do that?

我怎么能做到这一点?


更多回答
优秀答案推荐

The only clean way to achive that is to implement a Scheduler Task. A good way is to use a console command. Here is a tutorial how to implement:

实现这一点的唯一干净利落的方法是实现调度程序任务。一个不错的方法是使用控制台命令。以下是如何实施的教程:


https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/CommandControllers/Tutorial.html#console-command-tutorial

Https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/CommandControllers/Tutorial.html#console-command-tutorial


In the execute() method of the command you can then iterate all your custom entities, check the deadline field and change the state field if needed.
That would look something like this:

然后,在该命令的Execute()方法中,您可以迭代所有定制实体,检查Deadline字段,并根据需要更改State字段。它看起来就像这样:


public function execute()
{
$allMyEntities = $myEntityRepository->findAll();
foreach($allMyEntities as $myEntity)
{
if($myEntity->getDealine() <= $today)
{
$myEntity->setState("closed");
$myEntityRepository->update($myEntity);
}
}
}


That's not possible to handle clean in the database. TCA can only work if the record is edited and saved.

这不可能在数据库中处理CLEAN。只有在编辑并保存记录后,TCA才能工作。


That value is dynamic as it changes with the time when the record is evaluated/ read.

Though it is no data value but an evaluation value. You could build a getter for this value in the repository class or set the value in the controller.

该值是动态的,因为它会随着评估/读取记录的时间而变化。虽然它不是数据值,而是评估值。您可以在Repository类中为该值构建一个getter,或者在控制器中设置该值。


更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com