symfony2中的自定义实体生成错误

时间:2013-02-27 05:51:43

标签: symfony symfony-2.1 symfony-2.2

嗨我在不使用命令提示符的情况下创建自定义实体类。

这样我就创建了一个表名“profile”

包含以下字段。

id:       type = integer,Pk,
name:     type = string
lastname: type = string,
email:    type = string
gender:   type = enum('male','female'),
country:  type = string
state:     type = string,
city:     type='string',

现在我所做的是创建了一个名为“Profile.php”的实体类

  <?php

  namespace Blogger\BlogBundle\Entity;

  use Doctrine\ORM\Mapping as ORM;

 class Profile
{

protected $id;


protected $name;

protected $lastname;

protected $email;

protected $image;

protected $gender;

protected $city;

protected $state;

protected $country;


public function getName()
{
    return $this->name;
}

public function setName($name)
{
    $this->name = $name;
}

public function getLastName()
{
    return $this->lastname;
}
public function setLastName($lastname)
{
    $this->lastname = $lastname;
}

public function getEmail()
{
    return $this->email;
}
public function setEmail($email)
{
    $this->email = $email;
}

public function getImage()
{
    return $this->image;
}
public function setImage($image)
{
    $this->image = $image;
}

public function getGender()
{
    return $this->gender;
}
public function setGender($gender)
{
    $this->gender = $gender;
}

public function getCountry()
{
    return $this->country;
}
public function setCountry($country)
{
    $this->country = $country;
}

public function getState()
{
    return $this->state;
}
public function setState($state)
{
    $this->state = $state;
}

public function getCity()
{
    return $this->city;
}
public function setCity($city)
{
    $this->city = $city;
}
//public function   
}
?>
之后我创建了一个学说映射文件“Profile.orm.yml”。

Blogger\BlogBundle\Entity\Profile:
type: profile
table: null
repositoryClass: Blogger\BlogBundle\Entity\ProfileRepository
fields:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
    name:
        type: string
        length: '255'
    lastname:
        type: string
        length: '255'
    email:
        type: string
        length: '255'
    gender:
        type: string
        columnDefinition: enum('male','female')
    image:
        type: string
        length: '255'
    country:
        type: string
        length: '255'
    state:
        type: string
        length: '255'
    city:
        type: string
        length: '255'

lifecycleCallbacks: {  }

现在的问题是,当我调用配置文件页面时,显示了波纹管错误?

   Class "Blogger\BlogBundle\Entity\Profile" is not a valid entity or mapped super class. 

所以请告诉我有没有其他地方我不得不忘记编码。或当前文件中的错误部分。  coz,当我使用命令提示符生成实体时,创建了相同的2文件并且工作正常。

但我想自定义创建该文件,所以请帮助我。 感谢,

2 个答案:

答案 0 :(得分:1)

type: entity
table: profile

我应该这样做。

答案 1 :(得分:1)

首先它是YML,因此缩进很重要(并提高了可读性);)第二个它应该是&#34; entity&#34;不是&#34;个人资料&#34;

Blogger\BlogBundle\Entity\Profile:
    type: entity
    repositoryClass: Blogger\BlogBundle\Entity\ProfileRepository
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        name:
            type: string
            length: '255'
        lastname:
            type: string
            length: '255'
        email:
            type: string
            length: '255'
        gender:
            type: string
            columnDefinition: enum('male','female')
        image:
            type: string
            length: '255'
        country:
            type: string
            length: '255'
        state:
            type: string
            length: '255'
        city:
            type: string
            length: '255'
    lifecycleCallbacks: {  }

请使用php app/console doctrine:schema:validate任务检查您是否拥有有效的架构和映射信息。