2013-02-27 77 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 

應該做的伎倆,我認爲。