Php 如何在symfony中执行错误消息
我使用CRUD为实体生成操作。但是,我想修改编辑操作;例如,用户选择由1表示的“非活动”作为状态,然后将向他们显示一条错误消息,否则他们可以继续更新该行。在实体中,这些变量是Php 如何在symfony中执行错误消息,php,symfony,Php,Symfony,我使用CRUD为实体生成操作。但是,我想修改编辑操作;例如,用户选择由1表示的“非活动”作为状态,然后将向他们显示一条错误消息,否则他们可以继续更新该行。在实体中,这些变量是状态,支付PID,开始日期,结束日期 这就是编辑操作当前的样子 public function editAction($Paypid) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('co
状态
,支付PID
,开始日期
,结束日期
这就是编辑操作当前的样子
public function editAction($Paypid)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('comtwclagripayrollBundle:Payrollperiod')
->findBy(['paypid' => $Paypid, 'state' => 0]);
if (!$entity) {
$this->addFlash(
'notice',
'You cannot edit an inactive Payroll Period'
);
return $this->redirectToRoute('/payrollperiod');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($Paypid);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
And this method in the repository entity.
public function findByPaypidAndActiveState($Paypid)
{
return $this->getEntityManager()
->createQuery(
'SELECT p FROM comtwclagripayrollBundle:Payrollperiod
WHERE paypid = :paypid AND state = :state'
)
->setParameter('paypid', $Paypid)
->setParameter('state', 0)
->getResult();
}
可能添加以查看类似的内容(仅适用于细枝模板):
我建议正确地使用
标记。您能澄清触发错误的确切原因吗?如果在表单中选择一个特定的值,最好通过自定义验证来处理(请参见),但是如果您希望在用户具有特定状态时整个操作不可用,那么最好由安全层来处理。最后,您可以始终将自定义“flash消息”创建为错误,并且在某些情况下不允许使用表单。。请进一步详细描述您想要实现的目标。当用户选择非活动状态进行编辑时,应向他们发送一条错误消息,说明此状态无法编辑。我添加了类似的东西。像你这样的闪光灯是一个不错的解决方案,对吗?你还需要什么?我在addflash上有一个错误,因为我认为它做得不对。那就是我需要帮助的地方还有什么需要的吗。就像在twigno问题中一样,请将我的answear标记为对其他人有用
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
{{ flash_message }}
{% endfor %}
{% endfor %}