title: How to do error messages in symfony
body: <p>I have used CRUD to generate actions for an entity. However, I would like to modify the edit action; for instance, a user select 'inactive' represented by 1 for State then they will be shown an error message otherwise they can proceed to updating that row. Within the entity these are the variables <code>state</code>, <code>paypid</code>, <code>startDate</code>, <code>endDate</code>.</p>
  
  <p>This is what the edit action currently looks like.</p>
  
  <pre><code> public function editAction($Paypid)
  {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
  
      $entity = $em-&gt;getRepository('comtwclagripayrollBundle:Payrollperiod')
          -&gt;findBy(['paypid' =&gt; $Paypid, 'state' =&gt; 0]);
  
      if (!$entity) {
          $this-&gt;addFlash(
          'notice',
          'You cannot edit an inactive Payroll Period'
          );
  
          return $this-&gt;redirectToRoute('/payrollperiod');
      }
  
      $editForm = $this-&gt;createEditForm($entity);
      $deleteForm = $this-&gt;createDeleteForm($Paypid);
  
      return array(
          'entity'      =&gt; $entity,
          'edit_form'   =&gt; $editForm-&gt;createView(),
          'delete_form' =&gt; $deleteForm-&gt;createView(),
      );        
  }
  
  And this method in the repository entity.
  
  public function findByPaypidAndActiveState($Paypid)
  {
      return $this-&gt;getEntityManager()
          -&gt;createQuery(
              'SELECT p FROM comtwclagripayrollBundle:Payrollperiod 
                  WHERE paypid = :paypid AND state = :state'
          )
          -&gt;setParameter('paypid', $Paypid)
          -&gt;setParameter('state', 0)
          -&gt;getResult();
  }
  </code></pre>