title: How To Authenticate In Symfony2 Using Two Different Tables
body: <p>I have two tables in this project of mine. One table is for the site admin which stores all the admin users details, and the other table stores all the login data for clients to the site.</p>
  
  <p>At the moment, I can log in using the admin details fine. However, I am now trying to login with the client details and it doesn't seem to be working. So far, when a user clicks on a link it will go to /clientarea/login. This page loads up fine. But when I try to log in I get an error.</p>
  
  <p>The error I am getting is this:</p>
  
  <blockquote>
    <p>Unable to find the controller for path "/clientarea/login_check". Maybe you forgot to add the matching route in your routing configuration?</p>
  </blockquote>
  
  <p>In my security.yml file, I have the following code: (By the way, I'm using plaintext for development only, it will be changed when it goes live):</p>
  
  <pre><code>providers:
      admin_db:
          entity: { class: Shout\AdminBundle\Entity\User, property: username }
      client_db:
          entity: { class: Shout\AdminBundle\Entity\Userclients, property: username }
  
  encoders:
      Shout\AdminBundle\Entity\User: 
          algorithm: plaintext 
      Shout\AdminBundle\Entity\Userclients: 
          algorithm: plaintext 
  
  firewalls:
      secured_area:
          pattern: ^/
          anonymous: ~
          provider: admin_db
          form_login:
              check_path: /login_check
              login_path: /login
          logout:
              path:   /logout
              target: /index
      client_area:
          pattern: ^/
          anonymous: ~
          provider: client_db
          form_login:
              check_path: /clientarea/login_check
              login_path: /clientarea/login
          logout:
              path:   /clientarea/logout
              target: /index
  
  access_control:
      - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/admin, roles: ROLE_ADMIN }
      - { path: ^/clientarea/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/clientarea, roles: ROLE_USER }
  </code></pre>
  
  <p>In my routing.yml I have this code:</p>
  
  <pre><code>login:
      pattern:   /login
      defaults:  { _controller: ShoutAdminBundle:Security:login }
  
      login_check:
          pattern:   /login_check
  
      logout:
          pattern:   /logout
  
      clientlogin:
          pattern:   /clientarea/login
          defaults:  { _controller: ShoutAdminBundle:Security:clientlogin }
  
      clientlogin_check:
          pattern:   /clientarea/login_check
  
      clientlogout:
          pattern:   /clientarea/logout
  </code></pre>
  
  <p>Here is the code in the controller. The code is identical for the login and clientlogin functions, the only thing that is different is the twig file they point to:</p>
  
  <pre><code>$request = $this-&gt;getRequest();
  $session = $request-&gt;getSession();
  
  // get the login error if there is one
  if ($request-&gt;attributes-&gt;has(SecurityContext::AUTHENTICATION_ERROR)) {
      $error = $request-&gt;attributes-&gt;get(SecurityContext::AUTHENTICATION_ERROR);
  } else {
      $error = $session-&gt;get(SecurityContext::AUTHENTICATION_ERROR);
  }
  
  return $this-&gt;render('ShoutAdminBundle:Security:clientlogin.html.twig', array(
      // last username entered by the user
      'last_username' =&gt; $session-&gt;get(SecurityContext::LAST_USERNAME),
      'error'         =&gt; $error,
  ));
  </code></pre>
  
  <p>The action path of the Client Login form points to clientlogin_check.</p>
  
  <p>What am I doing wrong?</p>