开发者

Admin generator - Using different forms for "edit" and "new" actions

开发者 https://www.devze.com 2023-01-26 22:13 出处:网络
How do I configure 开发者_开发百科generator.yml so that it will use one form for the \"new\" action, and another for the \"edit\" action ? Two ways:

How do I configure 开发者_开发百科generator.yml so that it will use one form for the "new" action, and another for the "edit" action ?


Two ways:

1. Write your own admin configuration

This is the preferred method if there are significant differences between the two forms. This file goes in the config folder of the module. "moduleName" should be replaced with the name of the module.

class moduleNameGeneratorConfiguration extends BaseModuleNameGeneratorConfiguration
{ 
  public function getForm($object = null, $options = array())
  {
    $options = array_merge($this->getFormOptions(), $options);
    if ($object && $object->exists())
    {
      return new EditModelForm($object, $options);
    }
    else
    {
      return new NewModelForm($object, $options);          
    }
  }
}

2. Separate the logic inside of the form

This can get messy if there are significant differences, but you can simply call isNew inside of the form as necessary, e.g.

public function configure()
{
  if ($this->isNew())
  {
    //do new stuff
  }
  else
  {
    //do edit stuff
  }
}


You can create the same directory stucture as in the Frontend application, and it will override the generator forms. For example, create a indexSuccess.php file in your Backend module. When loading that module, it will use the indexSuccess.php file now.

The easiest way to go about doing this, is to copy data from your /cache folder -- Basically copy the generated backend module files, and modify them the way you want.


I was able to do different things in "new" and "edit" in the same form, using

$this->isNew() 


You can specify which field are available in a form depending on the action, see The form section only exists as a fallback for the edit and new sections.

For example :

generator:
  param:
      form: 
        display:
          group1:             [name, description]
      edit:
        title:                Edit item %%name%%
        fields: 
          #group1:             [name, description] -> inheritance 
          group2:             [only_displayed_when_editing_field]
      new:
        title:                New item
        fields:
          group1:             [name] #override
0

精彩评论

暂无评论...
验证码 换一张
取 消