好的,这必须是一个非常新手的问题,所以没有人问过它:) 所以我对这个问题表示歉意。 好。 这是实体:
<?php
// src/Alvent/LocalBundle/Entity/Note.php
namespace Alvent\LocalBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="Notes")
*/
class Note
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $Id;
/**
* @ORM\Column(type="text")
*/
protected $Note;
/**
* @ORM\Column(type="datetime", length=50)
*/
protected $Date;
//***************************************************************************************
//Getters and Setters
//***************************************************************************************
/**
* Get Id
*
* @return integer
*/
public function getId()
{
return $this->Id;
}
/**
* Set Note
*
* @param string $notes
* @return Organization
*/
public function setNote($note)
{
$this->Note = $note;
return $this;
}
/**
* Get Notes
*
* @return string
*/
public function getNote()
{
return $this->Note;
}
/**
* Set Date
*
* @param \DateTime $date
* @return Notes
*/
public function setDate($date)
{
$this->Date = $date;
return $this;
}
/**
* Get Date
*
* @return \DateTime
*/
public function getDate()
{
return $this->Date;
}
}
这是实体的生成管理员:
<?php
namespace Alvent\LocalBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
class NoteAdmin extends Admin
{
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('Id')
->add('Note')
->add('Date')
;
}
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('Id')
->add('Note')
->add('Date')
->add('_action', 'actions', array(
'actions' => array(
'show' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('Id')
->add('Note')
->add('Date')
;
}
/**
* @param ShowMapper $showMapper
*/
protected function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('Id')
->add('Note')
->add('Date')
;
}
}
问题: 在创建表单中,ID字段显示没有值,它不会让我保存而不输入一个值,一个dn当我这样做时,它确实不喜欢它becuae我没有setId功能(我不应该)。
Neither the property "Id" nor one of the methods "addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()" exist and have public access in class "Alvent\LocalBundle\Entity\Note".
500 Internal Server Error - NoSuchPropertyException
我尝试了很多东西,比如隐藏Id字段,删除它等等。我做错了什么?