首页 > 解决方案 > Symfony 4. 工作流程 initial_place 不起作用

问题描述

在 workflow.yml 我定义了 initial_place。

framework:
    workflows:
        case_workflow:
            type: 'workflow' # or 'state_machine'
            audit_trail:
                enabled: true
            marking_store:
                type: 'multiple_state' # or 'single_state'
                arguments:
                    - 'currentPlace'
            supports:
                - App\Entity\Cases\CoreCase

            initial_place: initial

            places:
                - initial
                - review
                - rejected
                - published

            transitions:
                to_review:
                    from: initial
                    to:   review
                publish:
                    from: review
                    to:   published
                reject:
                    from: review
                    to:   rejected

在我定义了属性的实体中

/**
 * @ORM\Column(type="string", length=50)
 */
private $currentPlace;

在控制器中,我创建实体并将其持久化

$dieselCase = new DieselCase();
$dieselCase->setUser($account);
$dieselCase->setCustomer($account);
$em->persist($dieselCase);
$em->flush();

但 currentPlace 未设置为初始值。它是工作流捆绑中的错误吗?我怎么解决这个问题?

标签: workflowsymfony4

解决方案


答案很晚,但是,这就是 Symfony 的工作方式null==initial_place

如果您使用WorkflowInterfaceand getMarking($dieselCase)when db is null,它将报告该位置['initial']与您配置的一样。或者如果你使用marking_store: type: 'single_state'它会报告'initial'

'currentPlace' 标记存储只会在您执行$workflow->apply($dieselCase, 'to_review')


推荐阅读