title: Getting Request and Session in Symfony 3 Controller
body: <p>I have a big problem and please help me. So I want to create an login system witch will use only users from : </p>
  
  <pre><code>providers:
    in_memory:
        memory:
            users:
  </code></pre>
  
  <p>So my global routing : <code>/app/config/routing.yml</code> :</p>
  
  <pre><code>app_admin:
      resource: "@AppAdminBundle/Resources/config/routing.yml"
      prefix:   /admin
  </code></pre>
  
  <p>My routing in AdminBundle : </p>
  
  <pre><code>app_admin_homepage:
      path:     /
      defaults: { _controller: AppAdminBundle:Login:index }
  login:
      path:   /login
      defaults:  { _controller: AppAdminBundle:Login:login }
  login_check:
      path:   /login_check
  </code></pre>
  
  <p>My LoginController : </p>
  
  <pre><code>&lt;?php
  
  namespace App\AdminBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\Security\Core\SecurityContext;
  
  class LoginController extends Controller
  {
  public function indexAction()
  {
      return $this-&gt;render('AppAdminBundle:Member:login.html.twig');
  }
  public function loginAction()
  {
      $request = $this-&gt;get('request');
      $session = $this-&gt;get('session');
  
      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);
          $session-&gt;remove(SecurityContext::AUTHENTICATION_ERROR);
      }
  
      return $this-&gt;render('AppAdminBundle:Member:login.html.twig', array(
          'last_username' =&gt; $session-&gt;get(SecurityContext::LAST_USERNAME),
          'error'         =&gt; $error,
      ));
  }
  }
  </code></pre>
  
  <p>My login.html.twig :</p>
  
  <pre><code>&lt;form class="login-form" action="{{ path('login_check') }}"&gt;
      &lt;div class="login-wrap"&gt;
          &lt;p class="login-img"&gt;&lt;i class="icon_lock_alt"&gt;&lt;/i&gt;&lt;/p&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon"&gt;&lt;i class="icon_profile"&gt;&lt;/i&gt;&lt;/span&gt;
              &lt;input type="text" id="username" name="_username" value="{{ last_username }}" class="form-control" placeholder="Username" autofocus&gt;
          &lt;/div&gt;
          &lt;div class="input-group"&gt;
              &lt;span class="input-group-addon"&gt;&lt;i class="icon_key_alt"&gt;&lt;/i&gt;&lt;/span&gt;
              &lt;input type="password" class="form-control" id="password" name="_password" placeholder="Password"&gt;
          &lt;/div&gt;
          &lt;button class="btn btn-primary btn-lg btn-block" type="submit"&gt;Login&lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And my security.yml : </p>
  
  <pre><code>security:
  role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_FMTI:        ROLE_FMTI
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  access_control:
        - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin, role: IS_AUTHENTICATED_ANONYMOUSLY }
  
  firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
  
    secured_area:
        pattern:    ^/admin
        anonymous: ~
        form_login:
            login_path:  /admin/login
            check_path:  /admin/login_check
  
  
   access_control:
    - { path: ^/admin, roles: ROLE_ADMIN }
  
   providers:
    in_memory:
        memory:
            users:
                admin: { password: 111111, roles: 'ROLE_FMTI' }
  
   encoders:
    Symfony\Component\Security\Core\User\User: plaintext
  </code></pre>
  
  <p>When I tried to access : <code>/admin/login</code> </p>
  
  <p>I get this error : <code>You have requested a non-existent service "request". Did you mean one of these: "router.request_context", "request_stack", "monolog.logger.request", "data_collector.request"?</code> </p>
  
  <p>Could you please help me ? Thanks in advance and sorry for my english</p>