2013-02-27 61 views
0

喜我创建一个自定义实体类,而无需使用命令提示符。自定义实体产生错误

让我创建一个表名“轮廓”

具有以下字段。

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文件被创建,并且工作正常产生的实体。

,但我想customlly创建的文件,所以请帮助我。 谢谢,

回答

1

,首先它是阳明如此压痕问题(和提高可读性);)第二个应该是类型“实体”而不是“个人资料”

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任务来检查是否有有效模式和映射信息。

1
type: entity 
table: profile 

应该做的伎俩,我认为。