0
votes

I've been reading and finding a solution for this problem since hours now. But it seems that I can't really fix this error I'm having some problem calling for my App\Form\CallCenterGroupsType;. Badly need help on this one.

Here's my CallCenterGroups class :

  <?php

namespace App\Entity;

use App\Repository\CallCenterGroupsRepository;
use Doctrine\ORM\Mapping as ORM;

/**
 * CallCenterCampaigns
 * 
 * @ORM\Entity(repositoryClass=CallCenterGroupsRepository::class)
 * @ORM\Table(name="call_center_groups")
 */
class CallCenterGroups
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     *  @ORM\Column(name="user_group", type="string", length=20, nullable=false)
     */
    private $userGroup;

    /**
     * @ORM\Column(name="callcenter_id", type="integer", nullable=false)
     */
    private $callcenterId;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getUserGroup(): ?string
    {
        return $this->userGroup;
    }

    public function setUserGroup(string $userGroup): self
    {
        $this->userGroup = $userGroup;

        return $this;
    }
/**
     * Set callcenterId
     *
     * @param integer callcenterId
     * @return CallCenterGroups
     */
    public function setCallcenterId($callcenterId) {
        $this->callcenterId = $callcenterId;

        return $this;
    }

    /**
     * Get callcenterId
     *
     * @return integer 
     */
    public function getCallcenterId() {
        return $this->callcenterId;
    }

}

Here's My CallCenterGroupsType :

   <?php

namespace App\Form;
use App\Entity\CallCenter;
use App\Entity\CallCenterGroups;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;


class CallCenterGroupsType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
           
            ->add('callcenterId', EntityType::class, array('label' => 'Centre d\'appel', 'class' => CallCenter::class, 'choice_label' => 'name', 
            'empty_data' => 'Choisissez un centre appel', 
            'multiple'    => true,
            'expanded'    => true,
            'required'    => false,
           
            'attr' => array('class' => 'form-control')))
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => CallCenterGroups::class,
        ]);
    }

    
}

here is my twig code :

{% extends 'superadmin.html.twig'%}
 
 
 {% block body %} 



        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-4 text-gray-800">Nouveau groupe</h1>

        </div>
  
      

   

                <div>
                    <!-- form start -->
                    {{ form_start(form)}}
                    <div>
                         <div class="row">
                                <div class="col-md-6">

                                 <div class="form-group">
                                        <label>{{ form_label(form_assignment.callcenterId) }}</label>
                                        {{ form_widget(form_assignment.callcenterId) }}
                                        <span class="text-danger">{{ form_errors(form_assignment.callcenterId) }}</span>
                                    </div>
                             
                                
                                    <div class="form-group">
                                        <label>{{ form_label(form.userGroup) }}</label>
                                        {{ form_widget(form.userGroup) }}
                                        <span class="text-danger">{{ form_errors(form.userGroup) }}</span>
                                        <div id="notification"></div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label>{{ form_label(form.allowedCampaigns) }}</label>
                                        {{ form_widget(form.allowedCampaigns) }}
                                        <span class="text-danger">{{ form_errors(form.allowedCampaigns) }}</span>
                                    </div>
                                    <div class="form-group">
                                        <label>{{ form_label(form.groupName) }}</label>
                                        {{ form_widget(form.groupName) }}
                                        <span class="text-danger">{{ form_errors(form.groupName) }}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                   
                    <div>
                        <button type="submit" class="btn btn-primary">Ajouter</button>
                      
                        <a class="btn btn-warning" href="">Retour</a>
                    </div>
                    {{ form_end(form)}}
    </div>
            </div>
        </div>
{% endblock %}                    

here is my CallCenter Class code :

 <?php

namespace App\Entity;

use App\Repository\CallCenterRepository;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=CallCenterRepository::class)
 */
class CallCenter
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\Column(type="string", length=10)
     */
    private $triptyque;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getTriptyque(): ?string
    {
        return $this->triptyque;
    }

    public function setTriptyque(string $triptyque): self
    {
        $this->triptyque = $triptyque;

        return $this;
    }
}

my controller code :

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\VicidialUserGroups;
use App\Entity\CallCenterGroups;
use App\Entity\CallCenter;
use App\Form\VicidialUserGroupsType;
use App\Form\CallCenterGroupsType;


class GroupeController extends AbstractController
{
    public function nouveauAction(Request $request): Response
    {
        $session = $request->getSession();
        if ($session->get('niveau') != 4){
           throw $this->createAccessDeniedException();
        }    
        $groupe = new VicidialUserGroups();
        $cappelgrp = new CallCenterGroups();


        
        
        $form = $this->createForm(VicidialUserGroupsType::class, $groupe);
        $form_assignment = $this->createForm(CallCenterGroupsType::class, $cappelgrp);
       
        $em = $this->getDoctrine()->getManager();
        $form->handleRequest($request);
        $form_assignment->handleRequest($request);


        if ($form->isSubmitted() || $form_assignment->isSubmitted()){
        $centreappel = $em->getRepository(CallCenter::class)->find($form->get('callcenterId')->getData());  
        $cappelgrp->setUserGroup($centreappel->getTriptyque() . '_' . $form->get('userGroup')->getData());
        $groupe->setUserGroup($centreappel->getTriptyque() . '_' . $groupe->getUserGroup());
        $groupe->setGroupName($centreappel->getTriptyque() . '_' . $groupe->getGroupName()); 
        $em->persist($groupe); 
        $em->persist($cappelgrp);
        $em->flush();



        }


        return $this->render('groupe/nouveau_groupe.html.twig', array('form' => $form->createView()   , 'form_assignment' =>$form->createView() ));
    }
}

i got this error :

Neither the property "callcenterId" nor one of the methods "callcenterId()", "getcallcenterId()"/"iscallcenterId()"/"hascallcenterId()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".

1
Get around the message by renaming CallCenterGroup::getCallcenterId to getcallcenterId. Things will probably still not work as desired because the Doctrine ORM deals with objects and not individual id's. Your callcenterId property should be a callcenter object. Not an id. Might review the product/category example in the docs. - Cerad
the error is in my twig code , i will update my post with my controler code cause i have 2 forms check it - Prototype
and i think something dosent work with : <div class="form-group"> <label>{{ form_label(form_assignment.callcenterId) }}</label> {{ form_widget(form_assignment.callcenterId) }} <span class="text-danger">{{ form_errors(form_assignment.callcenterId) }}</span> </div> - Prototype

1 Answers

0
votes

I'm not really sure about your overall method with two different forms instead of embedding one into the other. This is causing confusion for you and us. The error is stemming from the fact that you are passing the same FormView to both variables.

return $this->render('groupe/nouveau_groupe.html.twig', array(
  'form'            => $form->createView(),
  'form_assignment' => $form->createView() // this has NO callcenterId
));

(note how much easier it is to spot this when format your code a little differently)
It looks like you intended to do this:

return $this->render('groupe/nouveau_groupe.html.twig', array(
  'form'            => $form->createView(),
  'form_assignment' => $form_assignment->createView() // this has callcenterId
));

You also appear to be referencing the wrong form on this line:

$centreappel = $em->getRepository(CallCenter::class)->find($form->get('callcenterId')->getData());

That being said, I don't believe what you are doing follows best practice and I do not recommend it.