duanlian1320 2016-11-29 00:35
浏览 47
已采纳

Symfony 3错误:加载和声明的类名之间的大小写不匹配

i've just got this error

Case mismatch between loaded and declared class names: MyApp\UserBundle\Entity\post vs MyApp\UserBundle\Entity\Post

i'm using two controllers to do a specific operation of delete and getting back to the old page

here is my button's code

<a href="{{ path('DeleteComment',{'idc':comment.id}) }}"></a>
                                <a href="{{ path('DeleteComment',{'idc':comment.id}) }}"> <i
                                            class="icon-trash"></i>Delete</a>

here is my routing's code :

get_view_post:
path:     /blog/get/one/post/{id}/
defaults: { _controller: "MyAppBlogBundle:Blog:getpost" }
DeleteComment:
path:     /blog/post/comment/delete/{idc}/
defaults: { _controller: "MyAppBlogBundle:Blog:DeleteComment" }

here is my controllers code :

public function DeleteCommentAction($idc)
{

    $em = $this->getDoctrine()->getManager();
    $comment = $em->getRepository('MyAppUserBundle:PostComment')->find($idc);
    $idPost =$comment->getIdPost();


    $em->remove($comment);
    $em->flush();


    return $this->redirectToRoute("get_view_post", array('id' => $idPost));
}


 public function getpostAction($id)
{
    $user = $this->getUser();
    $idu = $user->getId();
    $em = $this->getDoctrine()->getManager();
    $em1 = $this->getDoctrine()->getManager();
    $post = $em->getRepository('MyAppUserBundle:Post')->find($id);
    $idPost=$post->getId();
    $comment = $em1->getRepository('MyAppUserBundle:PostComment')->findBy(array('idPost' => $idPost));
    return $this->render('MyAppBlogBundle::afficherPostAvecComment.html.twig', array('posts' => $post,'comments'=>$comment,'idu'=>$idu));

}

i'm declaring my entities like this :

use MyApp\UserBundle\Entity\Post;
use MyApp\UserBundle\Entity\PostComment;

Here is my Entity

namespace MyApp\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity
 * @ORM\Table(name="post")
 */
class Post
{


/**
 * @var integer
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;

/**
 * @var string
 * @ORM\Column(name="titre", type="string", length=100, nullable=false)
 */
private $titre;
/**
 * @var string
 * @ORM\Column(name="contenu", type="string", length=250, nullable=false)
 */
private $contenu;

/**
 * @var \DateTime
 * @ORM\Column(name="dateajout", type="datetime", nullable=true)
 */
private $dateajout ;

/**
 * @var integer
 * @ORM\ManyToOne(targetEntity="User")
 * @ORM\JoinColumn(name="id_utilisateur",referencedColumnName="id")
 */
private $idUser;

/**
 * @var integer
 * @ORM\Column(name="nbLike", type="integer", nullable=true)
 */
private $nbLike =0;
/**
 * @var integer
 * @ORM\Column(name="nbDislike", type="integer", nullable=true)
 */
private $nbDislike=0;
/**
 * @var integer
 * @ORM\Column(name="nbSignal", type="integer", nullable=true)
 */
private $nbSignal=0;
  • 写回答

1条回答 默认 最新

  • duanfang2708 2016-11-29 19:17
    关注

    i did some changes in my code, as i see My IDE couldn't differentiate between Post,PostComment and my array post or furthermore his own method of recuparation "_POST". you can see from the error above that it's based on hesitation between Post and post ,if you are using a latest version of symfony , try to scan you whole project and change the names of your attributes or classes ,believe it or not it creates some difficulties for the IDE when your project gets bigger

    and here is what made the error gone:

    • old

      /**

      • @var integer
      • @ORM\ManyToOne(targetEntity="post")
      • @ORM\JoinColumn(name="id_post",referencedColumnName="id") */ private $idPost;
    • new

      /**

      • @var integer
      • @ORM\ManyToOne(targetEntity="Post")
      • @ORM\JoinColumn(name="id_post",referencedColumnName="id") */ private $idPost;

    i was not giving the approvriate name of my Entity ,so when i do any operation based on foreign keys, the IDE won't find any Entity of reference

    if you are using and old version of symfony, you have to add a line of code in some file's configuration you can have a better explanation here:

    Symfony2 error : Case mismatch between loaded and declared class names:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效