desarrollo-cespi/pm-propel-generator-plugin

symfony1生成器的改进版本 - Propel风格

dev-master 2013-12-27 18:05 UTC

This package is not auto-updated.

Last update: 2024-09-24 01:51:15 UTC


README

pmPropelGeneratorPlugin通过将模块行为委托给表单,解耦了管理生成器和表单框架。此外,还向管理模块添加了显示操作。

安装

  • 通过composer
{
  "require": {
    "desarrollo-cespi/pm-propel-generator-plugin": "dev-master"
  }
}
  • 或者使用git,从源代码安装。

  • 清除缓存

  • 从现在起,您可以使用基本主题生成-admin

$ php symfony propel:generate-admin <app> ClassName --theme=basic
  • 该插件需要jQuery & jQuery.noConflict(). 这两个文件包含在插件的 'web/js' 路径中。首先加载jQuery,然后是 'no-conflict' 脚本,之后如果需要,再加载prototype。

配置

  • 在generator.yml中将pmPropelGenerator类设置为生成器和基本主题
generator:
  class: pmPropelGenerator
  param:
    # ...
    theme: basic
    # ...
  • 配置模块,就像配置标准管理生成器一样,除了在新建和编辑上下文中不再有字段配置和显示(仅在列表中,用于多排序配置)。

功能

  • 通过在表单中添加get{$action}Fieldsets方法支持每个操作的字段集
class Person extends sfFormPropel
{
  // ...

  public function getNewFieldsets()
  {
    return array(
      'NONE' => array('first_name', 'last_name'),
      'Address' => array('street', 'number', 'city_id')
    );
  }

  public function getEditFieldsets()
  {
    return $this->getNewFieldsets();
  }
}

仅适用于新建和编辑操作(显示操作类似于列表视图)。

  • 通过在表单中添加get{$action}Layout方法支持每个操作的布局
class Person extends sfFormPropel
{
  // ...

  public function getNewLayout()
  {
    return 'tabbed'; // or 'folded'
  }

  public function getEditLayout()
  {
    return 'folded'; // or 'tabbed'
  }
}

Also you can create another layouts, creating a partial. I.E., tabbed layout is coded in _form_tabbed.php and _show_form_tabbed.php.

* Fields and display configuration through the form for new, edit and show contexts.
* The forms are displayed in tables rather than divs (as originally in forms) and thus the partials are less than in the standard generator.
* Form formatters are used if defined.
* Object actions can be forbidden if a method is defined in the object. IE:

```php
class Person extends BasePerson
{
  /**
   * this method will be used to forbid the edit action in the generator
   */
  public function canEdit($sf_user)
  {
    return !$this->getLock();
  }
}

该方法接受一个参数:用户。

可以通过在Peer类中定义canNew方法禁止new操作。例如

class PersonPeer extends BasePersonPeer
{
  /**
   * this method will be used to forbid the new action in the generator
   */
  public function canNew($sf_user)
  {
    // do something...
    return true;
  }
}
  • 对象操作可以在条件成立时显示。例如
list:
  object_actions:
    _edit:
      show_when: canEdit
    # ...
  • 外部列排序。假设模型Person有一个外键:document_type_id,我们想要按document_type对列表列进行排序。在这种情况下需要这样做
list:
  fields:
    document_type:
      peer_column: DocumentTypePeer::NAME
  peer_method: doSelectJoinDocumentType
  display: [first_name, last_name, document_type, document_number]
  • 多排序
list:
  multiple_sort: true
  • 新的闪存消息

    • 'error':与之前相同。
    • 'error_params':这应该是一个数组,它将被用作__()方法的第二个参数。用于翻译。
    • 'error_detail':要在'error'消息下方显示的消息数组。
    • 'error_detail_params':与'error_params'类似,但用于'error_detail'消息。
    • 'notice':老样子。
    • 'notice_params':这应该是一个数组,它将被用作__()方法的第二个参数。
    • 'notice_detail':要在'notice'消息下方显示的消息数组。用于翻译。
    • 'notice_detail_params':与'notice_params'类似,但用于'notice_detail'消息。
    • 'warning':老样子。
    • 'warning_params':这应该是一个数组,它将被用作__()方法的第二个参数。用于翻译。
    • 'warning_detail':要在'warning'消息下方显示的消息数组。用于翻译。
    • 'warning_detail_params':与'warning_params'类似,但用于'warning_detail'消息。
  • 顶部操作

如果您想在表单或列表上方显示表单或列表操作,可以在generator.yml的'list'和'form'部分将'use_top_actions'设置为true。

list:
  use_top_actions: true
form:
  use_top_actions: true
  • 顶部分页

如果您想在列表上方显示分页器,可以在generator.yml的'list'部分将'use_top_pagination'设置为true。

list:
  use_top_pagination: true
  • 新的部分
    • 在每个列表元素中都有一个可以用来给每一行添加类的部分。输出代码类似于
<tr class="sf_admin_row <?php include_partial('sf_admin_row_extra_classes', array('object' => $object))">
  ...
</tr>
  • 将显示上下文作为列表上下文:显示和布局都是可用的。在这种情况下,布局在新建和编辑上下文中充当布局。例如,在带有标签页的布局中,生成器将渲染_show_form_tabbed.php部分。

使用方法如下

show:
  title: Showing something
  layout: tabbed
  display:
    First tab: [first_name, last_name]
    Second tab: [_full_id]

如你所见,你可以使用部分。

  • 一个新的表单格式化程序,它将"required"类添加到必需小部件的标签。用法
public function configure()
{
  $pm_formatter_table = new pmWidgetFormSchemaFormatterTable($this);
  $this->getWidgetSchema()->addFormFormatter("pm_table", $pm_formatter_table);
  $this->getWidgetSchema()->setFormFormatterName("pm_table");
}
  • 导出为CSV或EXCEL(需要sfPhpExcelPlugin插件才能工作)。请参阅EXPORTATION_DOCUMENTATION文件以获取完整文档。

  • customEdit

如果您正在尝试使用自定义表单(与在'edit'操作中使用的表单不同)修改一个对象,此插件提供了一个customEdit模板,使用以下变量:

  • dbObject : 正在更新的propel对象。

  • form : 用于编辑dbObject的表单。

  • custom_form_action : 发送表单信息的路由或'module/action'。

  • custom_title : 页面标题。

    当使用此插件时,模块Action类中的'simpleProcessForm'和'getObjectFromRequest'方法可能很有用。

    以下是一个使用此插件的示例:

public function executeEditInternalAreas(sfWebRequest $request)
{
  $this->Document             = $this->getRoute()->getObject();
  $this->form                 = $this->configuration->getEditInternalAreasForm($this->Document);
  $this->dbObject             = $this->form->getObject();
  $this->custom_form_action   = 'document/updateInternalAreas';
  $this->custom_title         = 'Edit internal areas of the document';

  $this->setTemplate('customEdit');
}

public function executeUpdateInternalAreas(sfWebRequest $request)
{
  $this->form                 = $this->configuration->getEditInternalAreasForm($this->getObjectFromRequest('document'));
  $this->dbObject             = $this->form->getObject();
  $this->custom_form_action   = 'document/updateInternalAreas';
  $this->custom_title         = 'Edit internal areas of the document';
  $this->simpleProcessForm($request, $this->form, '@document');

  $this->setTemplate('customEdit');
}
  • 列表标题
    • 如果在评估'indexSuccess' php代码时设置了名为'title'的变量,则其内容用作标题。
    • 如果在评估'indexSuccess' php代码时设置了名为'title_parameters'的变量,则其内容用作'title'的I18N参数。