MVC cannot use any other function than Find and FindOneBy

32 Views Asked by At

I have a project to do in PHP (MVC) with my university. Unfortunately, I've been stuck for a week, and nobody in the university knows where the problem is.

Error

Fatal error: Uncaught BadMethodCallException: Undefined method 'persist'. The method name must start with either findBy or findOneBy! in /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/lib/core/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:226 Stack trace: #0 /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/Cericar/model/utilisateurTable.class.php(40): Doctrine\ORM\EntityRepository->__call('persist', Array) #1 /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/Cericar/controller/mainController.php(58): utilisateurTable::registerUser('3', 'Id123', 'mdp123', 'Bye', 'ByeB') #2 /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/lib/core/context.class.php(52): mainController::testinscription(Array, Object(context)) #3 /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/CericarAjax.php(22): context->executeAction('testinscription', Array) #4 {main} thrown in /nfs/data01/data/uapv19/uapv1948/public_html/squelette_L3/lib/core/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php on line 226

When I try to use 'persist' or 'execute' or 'flush' I have the same error above.

// Inclusion de la classe utilisateur
require_once "utilisateur.class.php";

class utilisateurTable
{
    public static function getUserByLoginAndPass($login, $pass)
    {
        $em = dbconnection::getInstance()->getEntityManager();
        $userRepository = $em->getRepository('utilisateur');
        $user = $userRepository->findOneBy(array('identifiable => $login, 'pass' => sha1($pass)));
        if ($user == false) {
            echo 'Erreur SQL;
        }
        
        return $user;
    }

    public static function getUserById($id)
    {
        $em = dbconnection::getInstance()->getEntityManager();
        $userRepository = $em->getRepository('utilisateur');
        $user = $userRepository->findBy(array('id' => $id));
        if ($user == false) {
            echo 'Erreur SQL;
        }
        
        return $true;
    }

    public static function registerUser($id, $identifiant, $pass, $nom, $prenom)
    {
        $em = dbconnection::getInstance()->getEntityManager();
        $user = $em->getRepository('utilisateur');
        $user1 = new utilisateur;
        $user1->id = $id;
        $user1->identifiant = $identifiant;
        $user1->password = $pass;
        $user1->nom = $nom;
        $user1->prenom = $prenom;
        $user->persist($user1);
        $user->flush();
        
        return true;
    }
 }

Class

use Doctrine\Common\Collections\ArrayCollection;

class utilisateur
{
    public $id;
    public $identifiant;
    public $pass;
    public $nom;
    public $prenom;
    public $avatar;
}

Controller

class mainController
{
    public static function testinscription($request, $context)
    {
        $context->id = $_POST['id'];
        $context->identifiant = $_POST['identifiant'];
        $context->password = $_POST['password'];
        $context->nom = $_POST['nom'];
        $context->prenom = $_POST['prenom'];
        $context->utilisateur = utilisateurTable::registerUser($context->id, 
            $context->identifiant, $context->password,
            $context->nom, $context->prenom);

        return context::SUCCESS;
    }

    public static function FormInscription($request, $context)
    {
        return context::SUCCESS;
    }
}

So I tried different things to solve my problem, but even my colleague did not know where the problem was. So if you want any other file, ask.

0

There are 0 best solutions below