I'm trying to create a simple login. I created my Entity and had the form displaying on the page. This is the link I followed: http://symfony.com/doc/2.8/cookbook/security/form_login_setup.html
Error
This is the error I get when I hit the controller:
Error: Call to a member function get() on a non-object
After a bit of research and digging I discovered that because I am extending to the symfony controller that then in turn extends ContainerAware. I'm guessing that this is the issue?
Controller
<?php
namespace AppBundle\Controller\Security;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class SecurityController extends Controller
{
public function loginAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render(
'AppBundle:Loginpage:index.html.twig',
array(
// last username entered by the user
'last_username' => $lastUsername,
'error' => $error,
)
);
}
public function loginCheckAction()
{
//no logic needed
}
}
Service
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="controller.site.loginpage" class="AppBundle\Controller\Security\SecurityController">
<argument type="service" id="service_container" />
<argument type="service" id="templating"/>
</service>
</services>
Routing
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="loginpage" path="/login">
<default key="_controller">
controller.site.loginpage:loginAction
</default>
</route>