我正在使用Symfony 4.2版本 我做了一个工作流程服务,他负责三个地方的草稿,审阅和发布
我将这行代码添加到conf / products / framework.yaml中。但是我不明白代码中的currentPlace是什么。我通过此示例https://symfony.com/doc/4.2/workflow.html
工作workflows:
article_publishing:
type: 'workflow'
audit_trail:
enabled: true
marking_store:
type: 'multiple_state'
arguments:
- 'currentPlace'
supports:
- App\Entity\Article
initial_marking: draft
places:
-draft
-reviewed
-published
transitions:
to_review:
from: draft
to: reviewed
publish:
from: reviewed
to: published
但是当我刷新网站时,会出现此错误
Warning: array_map(): Argument #2 should be an array
答案 0 :(得分:0)
YAML配置的places
部分无效。
它应该看起来像这样:
places:
- draft
- reviewed
- published
注意减号和项目名称之间的空格
答案 1 :(得分:0)
我进行了更改,以便从类型中删除引号并删除参数,并添加了roved_by_admin,现在它可以正常工作了。
framework:
workflows:
article_publishing:
type: workflow
audit_trail: true
marking_store:
type: multiple_state
supports:
- App\Entity\Article
places:
- draft
- for_review
- approved_by_admin
- published
transitions:
to_for_review:
from: draft
to: for_review
to_approved_by_admin:
from: for_review
to: approved_by_admin
to_published:
from: approved_by_admin
to: published
to_draft:
from: for_review
to: draft
然后我将这段代码添加到Controller
/**
* @Route("/apply-transition/{article}", methods={"POST"})
*/
public function applyTransition(WorkflowInterface $articleWorkflow, Request $request, Article $article, RouterInterface $router)
{
$slug = $article->getCategory()->getSlug();
try {
$articleWorkflow->apply($article, $request->request->get('transition'));
$this->repository->flush();
} catch (ExceptionInterface $e) {
echo $e->getMessage();
}
$url = $router->generate('app_category_view', ([
'slug' => $slug,
]));
return new RedirectResponse($url);
}
/**
* @Route("/resetMarking/{article}", methods={"POST"})
*/
public function resetMarking(Article $article, RouterInterface $router)
{
$slug = $article->getCategory()->getSlug();
$article->setMarking([]);
$this->repository->flush();
$url = $router->generate('app_category_view', ([
'slug' => $slug,
]));
return new RedirectResponse($url);
}
在实体中添加此
/**
* @ORM\Column(type="json_array", nullable=true)
*/
private $marking;
/**
* @ORM\Column(type="json_array", nullable=true)
*/
private $transitionContexts;