I am trying to set up users in a project, but I receive errors because of the login path. It looks like an issue with spaces, but I tried with a php file and the error is the same.
FileLoaderLoadException: The routing file "/Applications/MAMP/htdocs/Symfony/app/config/routing.yml" contains unsupported keys for "login": "pattern". Expected one of: "resource", "type", "prefix", "path", "host", "schemes", "methods", "defaults", "requirements", "options", "condition" in /Applications/MAMP/htdocs/Symfony/app/config/routing.yml (which is being imported from "/Applications/MAMP/htdocs/Symfony/app/config/routing_dev.yml").
The code in app/config was :
login:
pattern: /login
defaults: { _controller: OCUserBundle:Security:login }
EDIT:
So I get the same error with a new project.
Here is what I am doing :
-Create 2 bundles (MGeneralBundle, MUserBundle) inside "Me", the namespace of my project.
-In app/config/routing.yml:
me_m_general:
resource: "@MeMGeneralBundle/Resources/config/routing.yml"
prefix: /
login:
path: /login
defaults: { _controller: MeMUserBundle:Security:login}
login_check:
path: /login_check
logout:
path: /logout
And in app/config/security.yml:
security:
in_memory:
memory: ~
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main_login:
# Cette expression régulière permet de prendre /login (mais pas /login_check !)
pattern: ^/login$
anonymous: true
main:
pattern: ^/
anonymous: false
provider: in_memory
form_login:
login_path: login
check_path: login_check
logout:
path: logout
target: /
And the controller for the login, with the routing.yml in the UserBundle :
me_home:
path: /
defaults: { _controller: MeMUserBundle:Default:index }
<?php
namespace Me\MUserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContext;
class SecurityController extends Controller
{
public function loginAction(Request $request)
{
if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
return $this->redirectToRoute('me_home');
}
$authenticationUtils = $this->get('security.authentication_utils');
return $this->render('MeMUserBundle:Security:login.html.twig', array(
'last_username' => $authenticationUtils->getLastUsername(),
'error' => $authenticationUtils->getLastAuthenticationError(),
));
}
}
The error is :
You have requested a non-existent service "security.context".
at : http://localhost:8888/Me/web/app_dev.php/login .
I don't know how to debug this.
patternis deprecated and removed for quite a while - simply replace it withpath. - Artamielsecurity.contexthas also been renamed since version 2.6. - Artamielsecurity.contextservice was deprecated in Symfony 2.6 and therefore was removed in Symfony 3.0. You need to user either thesecurity.token_storageorsecurity.authorization_checkerservice depending on what you want to do. - xabbuh