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 :

App\Entity\Post object not found by the @ParamConverter annotation.


Sujet :

Symfony PHP

  1. #1
    Membre éclairé
    Femme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2010
    Messages
    414
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2010
    Messages : 414
    Par défaut App\Entity\Post object not found by the @ParamConverter annotation.
    Bonjour

    Aidez-moi svp !

    J'ai tout à coup cette erreur que je ne comprend pas :
    App\Entity\Post object not found by the @ParamConverter annotation.
    Voici mon entity Post.php
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    <?php
     
    /*
     * This file is part of the Symfony package.
     *
     * (c) Fabien Potencier <fabien@symfony.com>
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */
     
     
    namespace App\Entity;
     
     
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
     
     
    /**
     * @ORM\Entity(repositoryClass="App\Repository\PostRepository")
     * @ORM\Table(name="symfony_demo_post")
     *
     * Defines the properties of the Post entity to represent the blog posts.
     *
     * See https://symfony.com/doc/current/book/doctrine.html#creating-an-entity-class
     *
     * Tip: if you have an existing database, you can generate these entity class automatically.
     * See https://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
     *
     * @author Ryan Weaver <weaverryan@gmail.com>
     * @author Javier Eguiluz <javier.eguiluz@gmail.com>
     * @author Yonel Ceruto <yonelceruto@gmail.com>
     */
    class Post
    {
        /**
         * Use constants to define configuration options that rarely change instead
         * of specifying them under parameters section in config/services.yaml file.
         *
         * See https://symfony.com/doc/current/best_practices/configuration.html#constants-vs-configuration-options
         */
        public const NUM_ITEMS = 5;
     
     
        /**
         * @var int
         *
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         */
        private $id;
     
     
        /**
         * @var string
         *
         * @ORM\Column(type="string")
         * @Assert\NotBlank
         */
        private $title;
     
     
        /**
         * @var string
         *
         * @ORM\Column(type="string")
         */
        private $slug;
     
     
        /**
         * @var string
         *
         * @ORM\Column(type="string")
         * @Assert\NotBlank(message="post.blank_summary")
         */
        private $summary;
     
     
        /**
         * @var string
         *
         * @ORM\Column(type="text")
         * @Assert\NotBlank(message="post.blank_content")
         * @Assert\Length(min=10, minMessage="post.too_short_content")
         */
        private $content;
     
     
        /**
         * @var \DateTime
         *
         * @ORM\Column(type="datetime")
         * @Assert\DateTime
         */
        private $publishedAt;
     
     
     
     
        /**
         * @var User
         *
         * @ORM\ManyToOne(targetEntity="App\Entity\User")
         * @ORM\JoinColumn(nullable=false)
         */
        private $author;
     
     
        /**
         * @var Comment[]|ArrayCollection
         *
         * @ORM\OneToMany(
         *      targetEntity="Comment",
         *      mappedBy="post",
         *      orphanRemoval=true,
         *      cascade={"persist"}
         * )
         * @ORM\OrderBy({"publishedAt": "DESC"})
         */
        private $comments;
     
     
        /**
         * @var Tag[]|ArrayCollection
         *
         * @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"})
         * @ORM\JoinTable(name="symfony_demo_post_tag")
         * @ORM\OrderBy({"name": "ASC"})
         * @Assert\Count(max="4", maxMessage="post.too_many_tags")
         */
        private $tags;
     
     
        public function __construct()
        {
            $this->publishedAt = new \DateTime();
            $this->comments = new ArrayCollection();
            $this->tags = new ArrayCollection();
            //$this->image = new UploadedFile();
        }
     
     
        public function getId(): int
        {
            return $this->id;
        }
     
     
        public function getTitle(): ?string
        {
            return $this->title;
        }
     
     
        public function setTitle(?string $title): void
        {
            $this->title = $title;
        }
     
     
        public function getSlug(): ?string
        {
            return $this->slug;
        }
     
     
        public function setSlug(?string $slug): void
        {
            $this->slug = $slug;
        }
     
     
        public function getContent(): ?string
        {
            return $this->content;
        }
     
     
        public function setContent(?string $content): void
        {
            $this->content = $content;
        }
     
     
        public function getPublishedAt(): \DateTime
        {
            return $this->publishedAt;
        }
     
     
        public function setPublishedAt(?\DateTime $publishedAt): void
        {
            $this->publishedAt = $publishedAt;
        }
     
     
        public function getAuthor(): User
        {
            return $this->author;
        }
     
     
        public function setAuthor(?User $author): void
        {
            $this->author = $author;
        }
     
     
        public function getComments(): Collection
        {
            return $this->comments;
        }
     
     
        public function addComment(?Comment $comment): void
        {
            $comment->setPost($this);
            if (!$this->comments->contains($comment)) {
                $this->comments->add($comment);
            }
        }
     
     
        public function removeComment(Comment $comment): void
        {
            $comment->setPost(null);
            $this->comments->removeElement($comment);
        }
     
     
        public function getSummary(): ?string
        {
            return $this->summary;
        }
     
     
        public function setSummary(?string $summary): void
        {
            $this->summary = $summary;
        }
     
     
        public function addTag(?Tag ...$tags): void
        {
            foreach ($tags as $tag) {
                if (!$this->tags->contains($tag)) {
                    $this->tags->add($tag);
                }
            }
        }
     
     
        public function removeTag(Tag $tag): void
        {
            $this->tags->removeElement($tag);
        }
     
     
        public function getTags(): Collection
        {
            return $this->tags;
        }
    }
    Mon controller :
    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    <?php
     
    namespace App\Controller;
     
     
    use App\Entity\Comment;
    use App\Entity\Post;
    use App\Entity\User;
    use App\Events;
    use App\Form\CommentType;
    use App\Repository\PostRepository;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    use Symfony\Component\EventDispatcher\GenericEvent;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
     
     
    /**
     * @Route("/post")
     */
    class BlogPostController extends Controller
    {
        /**
         * @Route("/", defaults={"page": "1"}, name="post_index", methods="GET")
         * @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated")
         */
        public function index(int $page, PostRepository $posts): Response
        {
            $latestPosts = $posts->findLatest($page);
            return $this->render('post/index.html.twig', ['posts' => $latestPosts]);
        }
     
     
     
     
        /**
         * @Route("/posts/{slug}", name="post_show", methods="GET")
         */
        public function show(Post $post): Response
        {
            return $this->render('post/show.html.twig', ['post' => $post]);
        }
     
     
        /**
         * @Route("/comment/{postSlug}/new", name="comment_new")
         * @Method("POST")
         * @Security("is_granted('IS_AUTHENTICATED_FULLY')")
         * @ParamConverter("post", options={"mapping": {"postSlug": "slug"}})
         *
         * NOTE: The ParamConverter mapping is required because the route parameter
         * (postSlug) doesn't match any of the Doctrine entity properties (slug).
         * See https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#doctrine-converter
         */
        public function commentNew(Request $request, Post $post, EventDispatcherInterface $eventDispatcher): Response
        {
            $comment = new Comment();
            $comment->setAuthor($this->getUser());
            $post->addComment($comment);
     
     
            $form = $this->createForm(CommentType::class, $comment);
            $form->handleRequest($request);
     
     
            if ($form->isSubmitted() && $form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($comment);
                $em->flush();
     
     
                // When triggering an event, you can optionally pass some information.
                // For simple applications, use the GenericEvent object provided by Symfony
                // to pass some PHP variables. For more complex applications, define your
                // own event object classes.
                // See https://symfony.com/doc/current/components/event_dispatcher/generic_event.html
                $event = new GenericEvent($comment);
     
     
                // When an event is dispatched, Symfony notifies it to all the listeners
                // and subscribers registered to it. Listeners can modify the information
                // passed in the event and they can even modify the execution flow, so
                // there's no guarantee that the rest of this controller will be executed.
                // See https://symfony.com/doc/current/components/event_dispatcher.html
                $eventDispatcher->dispatch(Events::COMMENT_CREATED, $event);
     
     
                return $this->redirectToRoute('blog_post', ['slug' => $post->getSlug()]);
            }
     
     
            return $this->render('post/comment_form_error.html.twig', [
                'post' => $post,
                'form' => $form->createView(),
            ]);
        }
     
     
        /**
         * This controller is called directly via the render() function in the
         * blog/post_show.html.twig template. That's why it's not needed to define
         * a route name for it.
         *
         * The "id" of the Post is passed in and then turned into a Post object
         * automatically by the ParamConverter.
         */
        public function commentForm(Post $post): Response
        {
            $form = $this->createForm(CommentType::class);
     
     
            return $this->render('post/_comment_form.html.twig', [
                'post' => $post,
                'form' => $form->createView(),
            ]);
        }
     
     
     
     
    }

  2. #2
    Nouveau candidat au Club
    Inscrit en
    Février 2010
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Février 2010
    Messages : 2
    Par défaut Resaisir les derniers use avec auto-complétion
    Bonjour

    J'ai eu le même cas Je l'ai réglé en resaisissant les derniers use (import)avec auto-complétion sans le copier-coller

    En espérant que cela t'aide...

    Cordialement

Discussions similaires

  1. Réponses: 1
    Dernier message: 09/01/2015, 16h49
  2. Réponses: 0
    Dernier message: 22/02/2010, 10h36
  3. Réponses: 3
    Dernier message: 09/04/2009, 17h38
  4. Type mismatch / Item not found in the collection.
    Par broise dans le forum VBA Access
    Réponses: 2
    Dernier message: 18/07/2008, 14h14
  5. [XMLRAD.COM] Not found on the toile
    Par Jean_Benoit dans le forum XMLRAD
    Réponses: 1
    Dernier message: 10/06/2006, 19h37

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