Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Symfony]Passage d'attribut Null

A2lix translation Form Bundle

    15 octobre 2018 à 16:20:36

    Bonjour 

    J'utilise A2lix Translation Form Bundle qui me génère une table école_translation pour une table école par exemple.

    ecole_translation contient seulement les attribut qui exigent une traduction. 

    J'ai une relation OneToOne entre c'est 2 tables. Pour chaque école ajoutée s'implique l'ajout d'une école traduite dans ecole_translation mais avec un id_ecole null ce qui me bloque lors de parcourir la table ecole_translation  . Je pas compris pourquoi !

    J'ai besoin de votre aide et Merci d'avance 

    Fichier DefaultController.php

    <?php
    
    namespace AppBundle\Controller\FrontOffice;
    
    use AppBundle\Entity\Ecole;
    use AppBundle\Repository\EcoleRepository;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\Routing\Annotation\Route;
    
    class DefaultController extends Controller
    {
        /**
         * @Route("/{_locale}", name="homepage", methods="GET")
         */
        public function indexAction(EcoleRepository $ecoleRepository, Request $request)
        {
            $em = $this->getDoctrine()->getManager();
            $paginator = $this->get('knp_paginator');
            $ecosImg = $em->getRepository('AppBundle:Ecole')->findAll();
    
            $ecoleAR=$em->getRepository('AppBundle:Ecole')->findAll();
            $ecolesAr=$paginator->paginate($ecoleAR,$request->query->get('page',1), 4);
            
            $ecolesTradFr=$em->getRepository('AppBundle:EcoleTranslation')->findAll();//ici mon probleme !
            $ecolesFr=$paginator->paginate($ecolesTradFr,$request->query->get('page',1), 4);
            return $this->render('FrontOffice/Accueil/accueil.html.twig'
                , array(
                    'ecosImg'=>$ecosImg,
                    'ecoleAr'=>$ecolesAr,
                    'ecoleFr'=>$ecolesFr,
                    'ecoles' => $ecoleRepository->findAll()));
    
    
    
        }
    }
    

    Fichier Ecole.php

    <?php
    
    namespace AppBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Gedmo\Mapping\Annotation as Gedmo;
    use Gedmo\Translatable\Translatable;
    use Knp\DoctrineBehaviors\Model as ORMBehaviors;
    use Symfony\Component\PropertyAccess\PropertyAccess;
    use Symfony\Component\Validator\Constraints as Assert;
    
    /**
     * Ecole
     *
     * @ORM\Table(name="ecole")
     * @ORM\Entity(repositoryClass="AppBundle\Repository\EcoleRepository")
     */
    class Ecole
    {
        use ORMBehaviors\Translatable\Translatable;
    
        /**
         * @var int
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
    
        /**
         * @var string
         *
         * @ORM\Column(name="nom", type="string", length=255)
         */
        private $nom;
    
        /**
         * @var string
         *
         * @ORM\Column(name="description", type="text", length=255)
    //     * @Gedmo\Translatable()
         */
        private $description;
    
        /**
         * @var string
         *
         * @ORM\Column(name="adresse", type="string", length=255)
         */
        private $adresse;
    
        /**
         * @var string
         *
         * @ORM\Column(name="email", type="string", length=255)
         */
        private $email;
    
        /**
         * @var integer
         *
         * @ORM\Column(name="numTel", type="integer", length=255)
         */
        private $numTel;
    
        /**
         * @var string
         *
         * @ORM\Column(name="gouvernorat", type="string", length=255)
         */
        private $gouvernorat;
    
        /**
         * @ORM\OneToOne(targetEntity="AppBundle\Entity\Image", cascade={"all"})
         */
        private $logo;
    
        /**
         * @ORM\OneToOne(targetEntity="AppBundle\Entity\EcoleTranslation", mappedBy="ecoTr")
         */
        private $eco;
    
        /**
         * @ORM\OneToOne(targetEntity="AppBundle\Entity\Eleve", mappedBy="ecole")
         */
        private $eleve;
        /**
         * @Assert\Valid()
         */
        protected $translations;
    
        public function __call($method, $arguments)
        {
            return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), $method);
        }
    
        /**
         * Get id
         *
         * @return int
         */
        public function getId()
        {
            return $this->id;
        }
    
        /**
         * Set nom
         *
         * @param string $nom
         *
         * @return Ecole
         */
        public function setNom($nom)
        {
            $this->nom = $nom;
    
            return $this;
        }
    
        /**
         * Get nom
         *
         * @return string
         */
        public function getNom()
        {
            return $this->nom;
        }
    
        /**
         * Set adresse
         *
         * @param string $adresse
         *
         * @return Ecole
         */
        public function setAdresse($adresse)
        {
            $this->adresse = $adresse;
    
            return $this;
        }
    
        /**
         * Get adresse
         *
         * @return string
         */
        public function getAdresse()
        {
            return $this->adresse;
        }
    
        /**
         * Set email
         *
         * @param string $email
         *
         * @return Ecole
         */
        public function setEmail($email)
        {
            $this->email = $email;
    
            return $this;
        }
    
        /**
         * Get email
         *
         * @return string
         */
        public function getEmail()
        {
            return $this->email;
        }
    
        /**
         * Set numTel
         *
         * @param string $numTel
         *
         * @return Ecole
         */
        public function setNumTel($numTel)
        {
            $this->numTel = $numTel;
    
            return $this;
        }
    
        /**
         * Get numTel
         *
         * @return string
         */
        public function getNumTel()
        {
            return $this->numTel;
        }
    
    
        /**
         * Set description
         *
         * @param string $description
         *
         * @return Ecole
         */
        public function setDescription($description)
        {
            $this->description = $description;
    
            return $this;
        }
    
        /**
         * Get description
         *
         * @return string
         */
        public function getDescription()
        {
            return $this->description;
        }
    
        /**
         * Set logo
         *
         * @param \AppBundle\Entity\Image $logo
         *
         * @return Ecole
         */
        public function setLogo(\AppBundle\Entity\Image $logo = null)
        {
            $this->logo = $logo;
    
            return $this;
        }
    
        /**
         * Get logo
         *
         * @return \AppBundle\Entity\Image
         */
        public function getLogo()
        {
            return $this->logo;
        }
    
        /**
         * Set gouvernorat
         *
         * @param string $gouvernorat
         *
         * @return Ecole
         */
        public function setGouvernorat($gouvernorat)
        {
            $this->gouvernorat = $gouvernorat;
    
            return $this;
        }
    
        /**
         * Get gouvernorat
         *
         * @return string
         */
        public function getGouvernorat()
        {
            return $this->gouvernorat;
        }
    
        /**
         * Set eco
         *
         * @param \AppBundle\Entity\EcoleTranslation $eco
         *
         * @return Ecole
         */
        public function setEco(\AppBundle\Entity\EcoleTranslation $eco = null)
        {
            $this->eco = $eco;
    
            return $this;
        }
    
        /**
         * Get eco
         *
         * @return \AppBundle\Entity\EcoleTranslation
         */
        public function getEco()
        {
            return $this->eco;
        }
    
        /**
         * Set eleve
         *
         * @param \AppBundle\Entity\Eleve $eleve
         *
         * @return Ecole
         */
        public function setEleve(\AppBundle\Entity\Eleve $eleve = null)
        {
            $this->eleve = $eleve;
    
            return $this;
        }
    
        /**
         * Get eleve
         *
         * @return \AppBundle\Entity\Eleve
         */
        public function getEleve()
        {
            return $this->eleve;
        }
    }

    Fichier Ecole_Translation.php

    <?php
    
    namespace AppBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use Knp\DoctrineBehaviors\Model as ORMBehaviors;
    
    /**
     * EcoleTranslation
     *
     * @ORM\Table(name="ecole_translation")
     * @ORM\Entity(repositoryClass="AppBundle\Repository\EcoleTranslationRepository")
     */
    class EcoleTranslation
    {
    
        use ORMBehaviors\Translatable\Translation;
    
        /**
         * @var string
         *
         * @ORM\Column(name="nomTrad", type="string", length=255)
         */
        private $nomTrad;
    
        /**
         * @var string
         *
         * @ORM\Column(name="adresseTrad", type="string", length=255)
         */
        private $adresseTrad;
    
        /**
         * @var string
         *
         * @ORM\Column(name="localeTrad", type="string", length=255)
         */
        private $localeTrad;
    
        /**
         * @var string
         *
         * @ORM\Column(name="descriptionTrad", type="string", length=255)
         */
        private $descriptionTrad;
    
        /**
         * @ORM\OneToOne(targetEntity="AppBundle\Entity\Ecole", inversedBy="eco", cascade={"all"})
         */
        private $ecoTr;
    
        /**
         * Set nomTrad
         *
         * @param string $nomTrad
         *
         * @return EcoleTranslation
         */
        public function setNomTrad($nomTrad)
        {
            $this->nomTrad = $nomTrad;
    
            return $this;
        }
    
        /**
         * Get nomTrad
         *
         * @return string
         */
        public function getNomTrad()
        {
            return $this->nomTrad;
        }
    
        /**
         * Set adresseTrad
         *
         * @param string $adresseTrad
         *
         * @return EcoleTranslation
         */
        public function setAdresseTrad($adresseTrad)
        {
            $this->adresseTrad = $adresseTrad;
    
            return $this;
        }
    
        /**
         * Get adresseTrad
         *
         * @return string
         */
        public function getAdresseTrad()
        {
            return $this->adresseTrad;
        }
    
        /**
         * Set localeTrad
         *
         * @param string $localeTrad
         *
         * @return EcoleTranslation
         */
        public function setLocaleTrad($localeTrad)
        {
            $this->localeTrad = $localeTrad;
    
            return $this;
        }
    
        /**
         * Get localeTrad
         *
         * @return string
         */
        public function getLocaleTrad()
        {
            return $this->localeTrad;
        }
    
        /**
         * Set descriptionTrad
         *
         * @param string $descriptionTrad
         *
         * @return EcoleTranslation
         */
        public function setDescriptionTrad($descriptionTrad)
        {
            $this->descriptionTrad = $descriptionTrad;
    
            return $this;
        }
    
        /**
         * Get descriptionTrad
         *
         * @return string
         */
        public function getDescriptionTrad()
        {
            return $this->descriptionTrad;
        }
    
        /**
         * Set ecoTr
         *
         * @param \AppBundle\Entity\Ecole $ecoTr
         *
         * @return EcoleTranslation
         */
        public function setEcoTr(\AppBundle\Entity\Ecole $ecoTr = null)
        {
            $this->ecoTr = $ecoTr;
    
            $this->ecoTr->setEco('translatable_id');
    
            return $this;
        }
    
        /**
         * Get ecoTr
         *
         * @return \AppBundle\Entity\Ecole
         */
        public function getEcoTr()
        {
            return $this->ecoTr;
        }
    }

    Fichier accueil.html.twig

    {% extends 'FrontOffice/base.html.twig' %}
    {% block body %}
        {{ include('frontOffice/includes/slider.html.twig') }}
    
    
        <section class="sponsors-logos style-two">
            <div class="your-logo wow fadeInUp">
                <div class="container">
                    <ul class="sponsors-slider">
                    {% for ecole in ecosImg %}
    
                            <li>
                                <div class="image-box"><a href="#"><img src="{{ asset(ecole.logo.webPath|imagine_filter('image_100_88')) }}" alt=""></a></div>
                            </li>
                    {% endfor %}
                    </ul>
                </div>
            </div>
        </section>
        <!--about section-->
        <!-- gallery_wrapper-->
        <div class="gallery_wrapper style-two" style="background-image:url('../FrontEnd/images/gallery/bg.jpg');">
            <div class="section-title text-center">
                <h3>{{ 'accueil.nosecole'|trans }}</h3>
                {#<p>The Love Boat soon will be making another run the Love Boat promises something for everyone</p>#}
            </div>
            <div class="gallery_item_container gallery_style_eight gallery_text container" id="mixitup_list">
                <div class="row">
                    {#<div class="col-lg-8">#}
                    {% if app.request.getLocale=='fr' %}
                    {% for ecole in ecoleAr %}
    
                    <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mix Economics Others Finance">
    
                        <div class="single_item">
                            <div class="img_holder">
                                <img src="{{ asset(ecole.logo.webPath|imagine_filter('image_300_180')) }}" alt="images" class="img-responsive">
                                <div class="overlay tran3s">
                                    <div class="link">
                                        <a href="{{ asset(ecole.logo.webPath|imagine_filter('image_300_180')) }}" class="fancybox"><i
                                                    class="flaticon-plus-symbol"></i></a>
                                    </div>
                                </div> <!-- End .overlay -->
                            </div> <!-- End .img_holder -->
                            <div class="content">
                                <a href="course-3.html"><h5>{{ ecole.nom  }}</h5></a>
                                <div class="reting-box">
                                    <i class="fa fa-star" aria-hidden="true"></i>
                                    <i class="fa fa-star" aria-hidden="true"></i>
                                    <i class="fa fa-star" aria-hidden="true"></i>
                                    <i class="fa fa-star" aria-hidden="true"></i>
                                    <i class="fa fa-star-half-o" aria-hidden="true"></i>
                                </div>
                                <p>{{ ecole.description|slice(0,30) }}</p>
                                <a href="{{ path('front_inscription_eleve',{'id':ecole.id}) }}">{{ 'accueil.insc'|trans }}</a>
                                <div class="price-many">$250</div>
                            </div> <!-- End .title -->
                            <ul class="content-text">
                                <li class="time-duration">
                                    <i class="fa fa-map-marker"></i>
                                   {{ ecole.gouvernorat }}
                                </li>
                                <li class="students">
                                    <i class="fa fa-phone"></i>
                                    {{ ecole.numTel }}
                                </li>
                            </ul>
                        </div>
    
                    </div>
                        <!-- End .single_item -->
                    {% endfor %}
    
                    {% endif %}
                </div>
                {#{{ knp_pagination_render(ecolesTradFr) }}#}
                        {% if app.request.getLocale=='ar' %}
                            {% for ecole in ecoleFr %}
                                <div class="col-lg-3 col-md-3 col-sm-12 col-xs-12 mix Economics Others Finance">
    
                                    <div class="single_item">
                                        <div class="img_holder">
                                            <img src="{{ asset(ecole.ecoTr.logo.webPath|imagine_filter('image_300_180')) }}" alt="images" class="img-responsive">
                                            <div class="overlay tran3s">
                                                <div class="link">
                                                    <a href="{{ asset(ecole.ecoTr.logo.webPath|imagine_filter('image_300_180')) }}" class="fancybox"><i
                                                                class="flaticon-plus-symbol"></i></a>
                                                </div>
                                            </div> <!-- End .overlay -->
                                        </div> <!-- End .img_holder -->
                                        <div class="content">
                                            <a href="course-3.html"><h5>{{ ecole.nomTrad  }}</h5></a>
                                            <div class="reting-box">
                                                <i class="fa fa-star" aria-hidden="true"></i>
                                                <i class="fa fa-star" aria-hidden="true"></i>
                                                <i class="fa fa-star" aria-hidden="true"></i>
                                                <i class="fa fa-star" aria-hidden="true"></i>
                                                <i class="fa fa-star-half-o" aria-hidden="true"></i>
                                            </div>
                                            <p>...{{ ecole.descriptionTrad|slice(0,30) }}</p>
                                            <a href="{{ path('front_inscription_eleve',{'id':ecole.id}) }}">{{ 'accueil.insc'|trans }}</a>
                                            <div class="price-many">$250</div>
                                        </div> <!-- End .title -->
                                        <ul class="content-text">
                                            <li class="time-duration">
                                                <i class="fa fa-map-marker"></i>
                                                {{ ecole.localeTrad }}
                                            </li>
                                            <li class="students">
                                                <i class="fa fa-phone"></i>
                                                {{ ecole.ecoTr.numTel }}
                                            </li>
                                        </ul>
                                    </div>
    
                                </div>
                                {#<!-- End .single_item -->#}
                            {% endfor %}
    
                        {% endif %}
    
    
                </div>
                {#{{ knp_pagination_render(ecolesAr) }}#}
    
                <div class="link-btn text-center">
                    <a href="course-3.html">{{ 'accueil.btnVoir'|trans }}</a>
                </div>
            </div> <!-- End #mixitup_list -->
        </div>
    {% endblock %}

    -
    Edité par H_KingBh 15 octobre 2018 à 16:21:54

    • Partager sur Facebook
    • Partager sur Twitter
      16 octobre 2018 à 8:12:12

      Bonjour,

      Je ne comprends pas pourquoi tu crées une école, tu crées la traduction mais tu ne les lies pas ?

      Si je suis ta logique, une traduction DOIT avoir une école donc pas du NULL possible

      • Partager sur Facebook
      • Partager sur Twitter
      $2b||!$2b

      [Symfony]Passage d'attribut Null

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown