0
特定の状態の活動を編集したいと思います。 0-非アクティブ、1-アクティブ、2-検証、3-closed。期間の状態が1の場合、ユーザーは編集を許可されます。それ以外の場合は、エラーが発生します。状態が@ 1であってもテストしている間も、ユーザーは引き続きエラーを取得します。 periodidはアクティビティテーブルの外部キーであり、stateはピリオドIDを持つ別のテーブルで、プライマリキーを持っています。私は特定の状態にある期間の活動を編集する - Symfony
リポジトリにこれを持って
public function findBytransid($payrollperiodid)
{
$repository=$this->getEntityManager()->getRepository('comtwclagripayrollBundle:Activity');
$qb = $repository->createQueryBuilder('a');
$qb->select('a','pp');
$qb->Join('a.payrollperiodid','pp');
$qb->where('pp.state = :state');
$qb->setParameter('state', 1);
return $results = $qb->getQuery()->getResult();
}
コントローラ
$entity = $em->getRepository('comtwclagripayrollBundle:Activity')
->createQueryBuilder('a')
->innerJoin('a.sectionid', 's')
->innerJoin('s.farmid', 'f')
->where('a.transid=:id')
->setParameter('id', $id)
->getQuery()->getSingleResult();
$state = $em->getRepository('AcmeDemoBundle:Activity')->findBytransid($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
} elseif ($state) {
$this->addFlash('error', 'ERROR! Cannot edit, this activity is active.');
return $this->redirect($this->generateUrl('activity'));
} else {
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
編集ユーザは期間は、次に1の状態と一致する活性をクリック例えば それを編集フォームのページに表示します。このアクティビティを編集することはできません。
を助け
を使用する方法を取得するに希望を構築し、どのようなデータ(DBレコード)あなたが期待されるものをテストし、実際の結果と明確に指定してください。 「ユーザーがエラーになる」とはどういう意味ですか?彼は何をすべきか? また、あなたのコントローラで$ entityとは何ですか? –
誰かが私を助けてくれますか? –