Reputation: 305
i have two tables news and news_category. for that i have created two mapping class using symfony command 'doctrine:mapping:convert'. the two file as bellow.
news.orm.yml.
News:
type: entity
table: news
fields:
newsId:
id: true
type: integer
unsigned: false
nullable: false
column: news_id
generator:
strategy: IDENTITY
newsTitle:
type: string
length: 255
fixed: false
nullable: false
column: news_title
newsDescription:
type: text
nullable: false
column: news_description
newsStatus:
type: string
length: 255
fixed: false
nullable: false
column: news_status
createdAt:
type: date
nullable: false
column: created_at
manyToOne:
category:
targetEntity: NewsCategory
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
category_id:
referencedColumnName: category_id
orphanRemoval: false
lifecycleCallbacks: { }
2). NewCategory.orm.yml
NewsCategory:
type: entity
table: news_category
fields:
categoryId:
id: true
type: integer
unsigned: false
nullable: false
column: category_id
generator:
strategy: IDENTITY
categoryTitle:
type: string
length: 255
fixed: false
nullable: false
column: category_title
categoryDescription:
type: text
nullable: false
column: category_description
lifecycleCallbacks: { }
after that i have used the another symfony command "doctrine:mapping:import" using this i have again generate two file in Entity folder News.php and NewsCategory.php
which is as bellow.
1) news.php
<?php
namespace Admin\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* News
*
* @ORM\Table(name="news")
* @ORM\Entity
*/
class News
{
/**
* @var integer
*
* @ORM\Column(name="news_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $newsId;
/**
* @var string
*
* @ORM\Column(name="news_title", type="string", length=255, nullable=false)
*/
private $newsTitle;
/**
* @var string
*
* @ORM\Column(name="news_description", type="text", nullable=false)
*/
private $newsDescription;
/**
* @var string
*
* @ORM\Column(name="news_status", type="string", length=255, nullable=false)
*/
private $newsStatus;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="date", nullable=false)
*/
private $createdAt;
/**
* @var \NewsCategory
*
* @ORM\ManyToOne(targetEntity="NewsCategory")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
* })
*/
private $category;
}
And, 2) NewCategory.php
namespace Admin\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* NewsCategory
*
* @ORM\Table(name="news_category")
* @ORM\Entity
*/
class NewsCategory
{
/**
* @var integer
*
* @ORM\Column(name="category_id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $categoryId;
/**
* @var string
*
* @ORM\Column(name="category_title", type="string", length=255, nullable=false)
*/
private $categoryTitle;
/**
* @var string
*
* @ORM\Column(name="category_description", type="text", nullable=false)
*/
private $categoryDescription;
}
the problem is now when i am creating the Entities using the "doctrine:generate:entities" it is giving me the following error.
D:\wamp\www\Symfony>php app/console doctrine:generate:entities AdminNewsBundle
Generating entities for bundle "AdminNewsBundle"
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'Admin.NewsBundle.Entity.News.orm.yml' for class 'Admi
n\NewsBundle\Entity\News'.
doctrine:generate:entities [--path="..."] [--no-backup] name
sorry for poor english please help me out come from this problem as i am new to symfony2
Upvotes: 0
Views: 3741
Reputation: 668
Try replacing the first line of YML with the entity name with naspace
Admin\NewsBundle\Entity\News:
for exemple.
Upvotes: 0
Reputation: 706
Try:
1) php app/console doctrine:mapping:convert yml ./src/Admin/NewsBundle/Resources/config/doctrine/metadata/orm --from-database --force --namespace="Admin\\NewsBundle\\Entity\\"
for Linux namespace="Admin\\NewsBundle\\Entity\\", for Win probably namespace="Admin\NewsBundle\Entity\\"
Watch that mapping is in right place, has correct names and correct syntax.
2) php app/console doctrine:mapping:import AdminNewsBundle annotation
3) php app/console doctrine:generate:entities AdminNewsBundle
Upvotes: 3