18

我想为 Sonata Admin Bundle 中的创建和编辑操作创建不同的字段配置。

$this->getSubject()->getId()除了签到还有什么方法可以确定Sonata\AdminBundle\Admin\Admin::configureFormFields()吗?

4

6 回答 6

31

你也可以这样做:

protected function configureFormFields(FormMapper $formMapper) {
  if ($this->isCurrentRoute('create')) {
    // CREATE
  }
  else {
    // EDIT
  }
}
于 2013-07-25T08:17:10.243 回答
2

和:

if($this->getRequest()->get($this->getIdParameter()) == null){
   // create
} else {
   // edit
}
于 2013-07-24T22:30:29.673 回答
1

我用这个:

$creationMode = ($this->id($this->getSubject()))?(false):(true);
if ($creationMode){
 //Ok
}
于 2015-02-09T12:16:46.227 回答
1

在版本 3.x 的奏鸣曲管理员中

  if ($this->isCurrentRoute('create')) {
    // CREATE
  }
  else {
    // EDIT
  }

在 3.x 版之前的奏鸣曲管理员中使用:

  $subject = $this->getSubject();
  if ($subject->isNew()) { 
    // CREATE
  }
  else {
    // EDIT
  }
于 2018-05-08T11:04:54.243 回答
0

你也可以这样做:

protected function configureFormFields(FormMapper $formMapper) {
  if ($this->isCurrentRoute('create')) {
    // CREATE
  }
  else {
    // EDIT
  }
}
于 2018-03-01T10:06:08.487 回答
0
public function getAction(): ?string
{
    if (! $this->getRequest()) {
        return null;
    }
    $pathArray = \explode('/', $this->request->getPathInfo());

    return \end($pathArray);
}
于 2019-03-04T15:50:59.177 回答