【问题标题】:Custom entity generation error in symfony2symfony2 中的自定义实体生成错误
【发布时间】:2014-03-09 06:03:53
【问题描述】:

您好,我正在创建自定义实体类而不使用命令提示符。

这样我就创建了一个表名“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. 

所以请告诉我是否还有其他地方我必须忘记编码。或当前文件中的错误部分。 因为,当我使用命令提示符生成实体时,会创建相同的 2 文件并且工作正常。

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

【问题讨论】:

    标签: symfony symfony-2.1 symfony-2.2


    【解决方案1】:

    首先它是 YML,所以缩进很重要(并提高可读性);)第二个应该是类型“实体”而不是“配置文件”

    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 任务检查您是否有有效的架构和映射信息。

    【讨论】:

      【解决方案2】:
      type: entity
      table: profile
      

      应该做我认为的伎俩。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-02
        • 1970-01-01
        • 2017-02-26
        • 2017-11-14
        • 1970-01-01
        相关资源
        最近更新 更多