Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I guess my problem is hidden in my code elsewhere since no suggestion works... guess it is too localized then.</p> <p>Anyways, I ended up having to solve it this way, "manually" without using the built-in functions for validation. Very annoying but it works. Before the ->isValid() call I added these...</p> <pre><code> //check for users with same name or email $nameOccupied = $this-&gt;checkNameOccupied($entity); if ($nameOccupied==1) { $error = new FormError("Det finns redan en användare med det namnet."); $form-&gt;get('username')-&gt;addError($error); } $emailOccupied = $this-&gt;checkEmailOccupied($entity); if ($emailOccupied==1) { $error = new FormError("Det finns redan en användare med den epostadressen."); $form-&gt;get('email')-&gt;addError($error); } if ($form-&gt;isValid()) { </code></pre> <p>Here is the actual checker..</p> <pre><code> /* check whether name of user already is in use */ private function checkNameOccupied($entity) { $name = $entity-&gt;getUsername(); //get company $currentCompany = $this-&gt;container-&gt;get('security.context')-&gt;getToken()-&gt;getUser()-&gt;getCompany(); $tempUsername = $entity-&gt;getUsername(); $needle = $currentCompany-&gt;getCompanyName() . "-" . $tempUsername; //look for entity with same name inside container $repository = $this-&gt;getDoctrine()-&gt;getRepository('BizTVUserBundle:User'); $query = $repository-&gt;createQueryBuilder('c') -&gt;where('c.username = :name') -&gt;setParameters(array('name' =&gt; $needle)) -&gt;getQuery(); $match = $query-&gt;getResult(); if(isset($match[0])) { //make sure we aren't validating against itself if ( $entity-&gt;getId() &amp;&amp; $entity-&gt;getId() == $match[0]-&gt;getId() ) { return false; } else { return true; } } else { return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload