Skip to content
Advertisement

get PHP function (Symfony 4.2)

I have the following error that I do not understand: “Attempted to call function “pasPointer” from namespace “AppController”.” The code that goes with it:

public function emargementsParCours(EntityManagerInterface $em, Request $request): Response
{
  $session = $this->get('session');
  $user = $this->getUser();
  $teacherId = $user->getId();
  $idCours = $request->get('idCours');
  //dd($idCours);
  $utilisateurEtudiant = $this->getDoctrine()->getRepository(Utilisateur::class)->find($user);

  $listeDePointage = $em->getRepository(ProfCours::class)->findHorairesParCours($em, $teacherId, $idCours);


  return $this->render('profEmargementsParCours.twig', array(
                                                     'listeDePointage' => $listeDePointage,
                                                     'prenom' => $user->getPrenomUtilisateur(), 
                                                     'nom' => $user->getNomUtilisateur()));
}

public function listeEmargementsPassesParCours(EntityManagerInterface $em, Request $request): Response
{
  $pasdePointage = pasPointer($idCours, $idDate, $idCreneau);

  return $this->render('panelProfListeEmargements.twig', array(
                                                     'pasdePointage' => $pasdePointage,
                                                     'prenom' => $user->getPrenomUtilisateur(), 
                                                     'nom' => $user->getNomUtilisateur()));
}

// function called
public function pasPointer($idCours, $idDate, $idCreneau) { 
// SQL function executed
    $requestPasPointer = "SELECT ec.etudiant
    FROM etudiant_cours ec
    left JOIN pointage po 
        inner JOIN utilisateur u 
           on u.id = po.utilisateur_etudiant_id
        inner JOIN cours_planning cp 
           on cp.id = po.cours_id 
          and cp.cours = :conditions_particulieres_generales_client
          and cp.plage_horaire_id = :conditions_particulieres_generales_client
          and cp.date_cours = :conditions_particulieres_generales_client
      ON po.utilisateur_etudiant_id = ec.etudiant
    where po.utilisateur_etudiant_id is null";              
    $exectPasPointer = $bdd->prepare( $requestPasPointer );
    $exectPasPointer->execute( array( 
    ':idCours' => $idCours,
    ':idDate' => $idDate,
    ':idCreneau' => $idCreneau
    ));
}

I want to get the result of the function, but i don’t understand this error. The functions are in the same Controller, i do a simple call. and idea? thank you!

Advertisement

Answer

I think your function pasPointer lives inside of your controller class. If this is the case, change this line:

$pasdePointage = pasPointer($idCours, $idDate, $idCreneau);

To:

$pasdePointage = $this->pasPointer($idCours, $idDate, $idCreneau);

You will notice the addition of $this-> in my suggestion. $this is a reference to the current object (the controller class) and -> is used to call a method on your controller class (if pasPointer is living in your controller class, it is a method of your class).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement