Symfony2 CRUD生成“;CRUD生成器希望实体对象具有主键字段&”;


Symfony2 CRUD generates "The CRUD generator expects the entity object has a primary key field..."

生成CRUD:时出现此错误

The CRUD generator expects the entity object has a primary key field named "id" with a getId() method.

我找不到使用id的字段,我已经检查了好几次了。

这就是原则:

Sifo'SchoolBundle'Entity'MstJabatan:
    type: entity
    table: mst_jabatan
    id:
        kode:
            type: string
            nullable: false
            length: 20
            fixed: false
            comment: ''
            id: true
            generator:
                strategy: IDENTITY
    fields:
        nama:
            type: string
            nullable: false
            length: 50
            fixed: false
            comment: ''
        otoritas:
            type: boolean
            nullable: false
            comment: ''
            default: '0'
        keterangan:
            type: string
            nullable: false
            length: 100
            fixed: false
            comment: ''
        aktif:
            type: boolean
            nullable: false
            comment: ''
            default: '1'
        timestamp:
            type: datetime
            nullable: false
            comment: ''
            default: CURRENT_TIMESTAMP
        operator:
            type: string
            nullable: false
            length: 20
            fixed: false
            comment: ''
    lifecycleCallbacks: {  }

这就是实体:

<?php
namespace Sifo'SchoolBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
/**
 * MstJabatan
 */
class MstJabatan
{
    /**
     * @var string
     */
    private $kode;
    /**
     * @var string
     */
    private $nama;
    /**
     * @var boolean
     */
    private $otoritas;
    /**
     * @var string
     */
    private $keterangan;
    /**
     * @var boolean
     */
    private $aktif;
    /**
     * @var 'DateTime
     */
    private $timestamp;
    /**
     * @var string
     */
    private $operator;

    /**
     * Get kode
     *
     * @return string 
     */
    public function getKode()
    {
        return $this->kode;
    }
    /**
     * Set nama
     *
     * @param string $nama
     * @return MstJabatan
     */
    public function setNama($nama)
    {
        $this->nama = $nama;
        return $this;
    }
    /**
     * Get nama
     *
     * @return string 
     */
    public function getNama()
    {
        return $this->nama;
    }
    /**
     * Set otoritas
     *
     * @param boolean $otoritas
     * @return MstJabatan
     */
    public function setOtoritas($otoritas)
    {
        $this->otoritas = $otoritas;
        return $this;
    }
    /**
     * Get otoritas
     *
     * @return boolean 
     */
    public function getOtoritas()
    {
        return $this->otoritas;
    }
    /**
     * Set keterangan
     *
     * @param string $keterangan
     * @return MstJabatan
     */
    public function setKeterangan($keterangan)
    {
        $this->keterangan = $keterangan;
        return $this;
    }
    /**
     * Get keterangan
     *
     * @return string 
     */
    public function getKeterangan()
    {
        return $this->keterangan;
    }
    /**
     * Set aktif
     *
     * @param boolean $aktif
     * @return MstJabatan
     */
    public function setAktif($aktif)
    {
        $this->aktif = $aktif;
        return $this;
    }
    /**
     * Get aktif
     *
     * @return boolean 
     */
    public function getAktif()
    {
        return $this->aktif;
    }
    /**
     * Set timestamp
     *
     * @param 'DateTime $timestamp
     * @return MstJabatan
     */
    public function setTimestamp($timestamp)
    {
        $this->timestamp = $timestamp;
        return $this;
    }
    /**
     * Get timestamp
     *
     * @return 'DateTime 
     */
    public function getTimestamp()
    {
        return $this->timestamp;
    }
    /**
     * Set operator
     *
     * @param string $operator
     * @return MstJabatan
     */
    public function setOperator($operator)
    {
        $this->operator = $operator;
        return $this;
    }
    /**
     * Get operator
     *
     * @return string 
     */
    public function getOperator()
    {
        return $this->operator;
    }
}

使用以下命令生成:

php app/console doctrine:generate:crud --entity=SifoSchoolBundle:MstJabatan --route-prefix=sifo_MstJabatan --with-write --format=yml

究竟是什么导致了这个问题?

您已经覆盖了默认的id行为

id:
        kode:
            type: string
            nullable: false
            length: 20
            fixed: false
            comment: ''
            id: true
            generator:
                strategy: IDENTITY

所以现在您的id字段在实体中被称为kode。CRUD生成器被配置为只处理实体中的ID字段,而他在自动生成的实体中根本找不到属性$ID和方法getId()。

您可以将字段名从kode更改为id,并使别名getter成为getKode()方法,或者通过修改其他实体生成的crud文件来编写crud self