erreur : Attempted to call function "User" from namespace
Bonjour,
J'aimerais svp une aide concernant l'erreur :
Citation:
PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionEx
ception: Attempted to call function "User" from namespace "AppBundle\DataFixture
s\ORM". in
Mon controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends Controller
{
/**
* @Route("/login", name="login")
*/
public function loginAction(Request $request, AuthenticationUtils $authenticationUtils)
{
$errors = $authenticationUtils->getLastAuthenticationError();
$lastUserName = $authenticationUtils->getLastUsername();
return $this->render('AppBundle:Login:login.html.twig', array(
'errors' => $errors,
'username' => $lastUserName
));
}
} |
Mon LoadUserData.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <?php
namespace AppBundle\DataFixtures\ORM;
use AppBundle\Entity\User;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LoadUserData implements FixtureInterface, ContainerAwareInterface
{
private $container;
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$user = User();
$user->setUsername('mouss');
$user->setEmail('admin@mouss.com');
$encoder = $this->container->get('security.password_encoder');
$password = $encoder->encodePassword($user, '0101');
$user->setPassword($password);
$manager->persist($user);
$manager->flush();
}
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
} |
Mon login.html.twig
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| {% extends "::base.html.twig" %}
{% block body %}
<div class="panel-heading">
<h3>Connexion</h3>
</div>
<div class="panel-body">
{% if errors %}
<div class="alert alert-danger">
{{ errors.messageKey }}
</div>
{% endif %}
<form action="{{ path('login') }}" method="post">
<div class="input-group">
<label for="username">Username</label>
<input type="text" name="_username" id="username" value="{{ username }}" class="input-group">
</div>
<div class="input-group">
<label for="password">Password</label>
<input type="text" name="_password" id="password" class="input-group">
</div>
<br>
<button type="submit" class="btn btn-light">Sign In</button>
</form>
</div>
{% endblock %} |
C'est un tuto que j'ai reproduis exactement comme c'est fait dans le tuto . Mais j'ai l'erreur en question quand je fais la commande :
Citation:
php bin/console doctrine:fixtures:load