am working on symfony2 and am geting this error:
No mapping file found named 'Acme.BlogBundle.Entity.Posts.php' for class 'Acme\BlogBundle\Entity\Posts'. 500 Internal Server Error - MappingException
I generate Entity php app/console doctrine:generate:entity
Name of entity: AcmeBlogBundle:Post
Format: php
All that i put in Acme:BlogBundle:Entity directory.
This is my Entity Post class with getter and setter methds:
<?php
namespace Acme\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Posts
*/
class Posts
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $shortText;
/**
* @var string
*/
private $longText;
/**
* @var string
*/
private $author;
/**
* @var \DateTime
*/
private $dateCreated;
/**
* @var \DateTime
*/
private $dateModified;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Posts
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set shortText
*
* @param string $shortText
* @return Posts
*/
public function setShortText($shortText)
{
$this->shortText = $shortText;
return $this;
}
/**
* Get shortText
*
* @return string
*/
public function getShortText()
{
return $this->shortText;
}
/**
* Set longText
*
* @param string $longText
* @return Posts
*/
public function setLongText($longText)
{
$this->longText = $longText;
return $this;
}
/**
* Get longText
*
* @return string
*/
public function getLongText()
{
return $this->longText;
}
/**
* Set author
*
* @param string $author
* @return Posts
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
* @return Posts
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Set dateModified
*
* @param \DateTime $dateModified
* @return Posts
*/
public function setDateModified($dateModified)
{
$this->dateModified = $dateModified;
return $this;
}
/**
* Get dateModified
*
* @return \DateTime
*/
public function getDateModified()
{
return $this->dateModified;
}
}
In my controller i first set Post Entity after definig namespace of controller.
use Acme\BlogBundle\Entity\Posts;
After that i create method
public function AddAction()
{
// $post = Acme\BlogBundle\Entity\Posts()
$posts = new Posts();
$posts->setTitle('Test Title');
$em = $this->getDoctrine()->getManager();
$em->persist($posts);
$em->flush();
}
Here is and Stack Trace output
[1] Doctrine\Common\Persistence\Mapping\MappingException: No mapping file found named 'Acme.BlogBundle.Entity.Posts.php' for class 'Acme\BlogBundle\Entity\Posts'. at n/a in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php line 74
at Doctrine\Common\Persistence\Mapping\MappingException::mappingFileNotFound('Acme\BlogBundle\Entity\Posts', 'Acme.BlogBundle.Entity.Posts.php') in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/DefaultFileLocator.php line 117
at Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator->findMappingFile('Acme\BlogBundle\Entity\Posts') in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/PHPDriver.php line 59
at Doctrine\Common\Persistence\Mapping\Driver\PHPDriver->loadMetadataForClass('Acme\BlogBundle\Entity\Posts', object(ClassMetadata)) in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php line 104
at Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('Acme\BlogBundle\Entity\Posts', object(ClassMetadata)) in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php line 113
at Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata),
null, false, array()) in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php line 302
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('Acme\BlogBundle\Entity\Posts') in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
line 205
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Acme\BlogBundle\Entity\Posts') in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 268
at Doctrine\ORM\EntityManager->getClassMetadata('Acme\BlogBundle\Entity\Posts') in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1580
at Doctrine\ORM\UnitOfWork->doPersist(object(Posts), array('000000000d824498000000009cdc8511' => object(Posts))) in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1555
at Doctrine\ORM\UnitOfWork->persist(object(Posts)) in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php line 565
at Doctrine\ORM\EntityManager->persist(object(Posts)) in /var/www/html/Symfony/src/Acme/BlogBundle/Controller/DefaultController.php line 23
at Acme\BlogBundle\Controller\DefaultController->indexAction() in line
at call_user_func_array(array(object(DefaultController), 'indexAction'), array()) in /var/www/html/Symfony/app/bootstrap.php.cache line 2815
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1') in /var/www/html/Symfony/app/bootstrap.php.cache line 2789
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true) in /var/www/html/Symfony/app/bootstrap.php.cache line 2918
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true) in /var/www/html/Symfony/app/bootstrap.php.cache line 2220
at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) in /var/www/html/Symfony/web/app_dev.php line 28
Update:
New Entity Test:
<?php
// src/Acme/BlogBundle/Entity/Test.php
namespace Acme\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity
*/
class Test
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="short_text", type="string", length=255)
*/
private $shortText;
/**
* @var string
*
* @ORM\Column(name="long_text", type="text")
*/
private $longText;
/**
* @var \DateTime
*
* @ORM\Column(name="date_created", type="datetime")
*/
private $dateCreated;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Test
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set shortText
*
* @param string $shortText
* @return Test
*/
public function setShortText($shortText)
{
$this->shortText = $shortText;
return $this;
}
/**
* Get shortText
*
* @return string
*/
public function getShortText()
{
return $this->shortText;
}
/**
* Set longText
*
* @param string $longText
* @return Test
*/
public function setLongText($longText)
{
$this->longText = $longText;
return $this;
}
/**
* Get longText
*
* @return string
*/
public function getLongText()
{
return $this->longText;
}
/**
* Set dateCreated
*
* @param \DateTime $dateCreated
* @return Test
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* @return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
}
Again the some error
$ php app/console doctrine:generate:entities AcmeBlogBundle
Generating entities for bundle "AcmeBlogBundle"
[RuntimeException]
Bundle "AcmeBlogBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name