IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Erreur Neither the property "name"


Sujet :

Symfony PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Inscrit en
    Juin 2007
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 63
    Par défaut Erreur Neither the property "name"
    Bonjour,

    je suis entrain de chipoter avec mongoDB dans SF2. Tout se passe bien juste qu'a l'édition d'une category ou il me sort une erreur que je n'ai jamais vu avec les entities :

    Neither the property "name" nor one of the methods "getName()", "isName()", "hasName()", "__get()" or "__call()" exist and have public access in class "Doctrine\ODM\MongoDB\LoggableCursor".
    Voici mon Document Category :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    <?php
     
    namespace Site\StoreBundle\Document;
     
    use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
     
    /**
     * @MongoDB\Document
     */
    class Category
    {
        /**
         * @MongoDB\Id
         */
        protected $id;
     
        /**
         * @MongoDB\String
         */
        protected $name;
     
        /**
         * @MongoDB\ReferenceMany(targetDocument="Product")
         */
        private $products = array();
     
        public function __contructor() {
            $this->products = new \Doctrine\Common\Collections\ArrayCollection();  
        }
     
        /**
         * Get id
         *
         * @return id $id
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set name
         *
         * @param string $name
         * @return self
         */
        public function setName($name)
        {
            $this->name = $name;
            return $this;
        }
     
        /**
         * Get name
         *
         * @return string $name
         */
        public function getName()
        {
            return $this->name;
        }
     
        public function getProducts() {
            return $this->products;
        }
        public function __construct()
        {
            $this->products = new \Doctrine\Common\Collections\ArrayCollection();
        }
     
        /**
         * Add product
         *
         * @param Site\StoreBundle\Document\Product $product
         */
        public function addProduct(\Site\StoreBundle\Document\Product $product)
        {
            $this->products[] = $product;
        }
     
        /**
         * Remove product
         *
         * @param Site\StoreBundle\Document\Product $product
         */
        public function removeProduct(\Site\StoreBundle\Document\Product $product)
        {
            $this->products->removeElement($product);
        }
    }
    mon Document Product :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    <?php
     
    namespace Site\StoreBundle\Document;
     
    use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
     
    /**
     * @MongoDB\Document
     */
    class Product
    {
        /**
         * @MongoDB\Id
         */
        protected $id;
     
        /**
         * @MongoDB\String
         */
        protected $name;
     
        /**
         * @MongoDB\Float
         */
        protected $price;
     
        /**
         * @MongoDB\ReferenceOne(targetDocument="Category")
         */
        private $category;
     
        /**
         * Get id
         *
         * @return id $id
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set name
         *
         * @param string $name
         * @return self
         */
        public function setName($name)
        {
            $this->name = $name;
            return $this;
        }
     
        /**
         * Get name
         *
         * @return string $name
         */
        public function getName()
        {
            return $this->name;
        }
     
        /**
         * Set price
         *
         * @param float $price
         * @return self
         */
        public function setPrice($price)
        {
            $this->price = $price;
            return $this;
        }
     
        /**
         * Get price
         *
         * @return float $price
         */
        public function getPrice()
        {
            return $this->price;
        }
     
        /**
         * Set category
         *
         * @param Site\StoreBundle\Document\Category $category
         * @return self
         */
        public function setCategory(\Site\StoreBundle\Document\Category $category)
        {
            $this->category = $category;
            return $this;
        }
     
        /**
         * Get category
         *
         * @return Site\StoreBundle\Document\Category $category
         */
        public function getCategory()
        {
            return $this->category;
        }
    }
    Et l'action edit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
        public function editCategoryAction($id) {
            $category = $this->get('doctrine_mongodb')->getManager()->getRepository('SiteStoreBundle:Category')->findById($id);
     
            $form     = $this->createFormBuilder($category)
                             ->add('name')
                             ->getForm();
     
            $request  = $this->get('request');
     
            if($request->isMethod('POST')) {
     
                $form->bind($request);
     
                if ($form->isValid()) {
     
                    $update = $this->get('doctrine_mongodb')->getManager();
                    $update->persist($category);
                    $update->flush();
                    return $this->redirect($this->generateUrl('home'));
                }
            }
     
            return $this->render('SiteStoreBundle:Default:editCategory.html.twig', array(
                'form' => $form->createView(),
                'category' => $category
            ));
        }
    C'est surement tout con, mais je ne vois vraiment pas.

    Merci à vous

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2012
    Messages
    41
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Novembre 2012
    Messages : 41
    Par défaut
    Salut,

    Dans le message d'erreur de Doctrine on dirait que c'est la classe LoggableCursor, qui est native de MongoDB non ? (Je ne suis sûr de rien, je n'ai jamais utilisé Symfony2 et MongoDB ensemble).

    Une piste de ce côté-là peut-être ?

  3. #3
    Membre émérite
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    725
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juin 2011
    Messages : 725
    Par défaut
    Bonjour,

    je suppose que tu récupères une collection d'objets alors que tu ne veux en récupérer qu'un seul

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $category =$this->get('doctrine_mongodb')->getManager()->getRepository('SiteStoreBundle:Product')->find($id);
    // pourquoi l'appeler $category si c'est un objet Product??
    http://www.doctrine-project.org/api/...epository.html

  4. #4
    Membre actif
    Homme Profil pro
    Inscrit en
    Juin 2007
    Messages
    63
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Juin 2007
    Messages : 63
    Par défaut
    Merci pour vos réponses

    Oui grosse erreur de ma part, mais ça ne change rien l'erreur reste la même


    ca doit venir de ce bloc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            $form     = $this->createFormBuilder($category)
                             ->add('name')
                             ->getForm();
    Si change par id, la il change de discours en mettant :

    Neither the property "id" nor one of the methods "getId()", "isId()", "hasId()", "__get()" or "__call()" exist and have public access in class "Doctrine\ODM\MongoDB\LoggableCursor".
    ps: j'ai vidé mes caches à la main

    merci

Discussions similaires

  1. Réponses: 3
    Dernier message: 24/03/2014, 16h34
  2. [STRUTS] ApplicationResources.properties "s'efface"
    Par Gildas Huart dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 17/05/2005, 18h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo