Symfony中的默认表单 - 添加新输入和更改选项

时间:2011-06-24 17:54:38

标签: php symfony1 doctrine symfony-1.4

我的schema.yml:

User:
  columns:
    id:
      type: integer(4)
      autoincrement: true
      primary: true
    username:
      type: string(255)
    password:
      type: string(255)
  attributes:
    export: all
    validate: true

Group:
  tableName: group_table
  columns:
    id:
      type: integer(4)
      autoincrement: true
      primary: true
    name:
      type: string(255)
  relations:
    Users:
      foreignAlias: Groups
      class: User
      refClass: GroupUser

GroupUser:
  columns:
    group_id:
      type: integer(4)
      primary: true
    user_id:
      type: integer(4)
      primary: true
  relations:
    Group:
      foreignAlias: GroupUsers
    User:
      foreignAlias: GroupUsers
additional:
  columns:
    id:
      type: integer(4)
      autoincrement: true
      primary: true
    new:
      type: string(255)
  attributes:
    export: all
    validate: true

我生成了新模块:

  

php symfony doctrine:generate-module   --with-show --non-verbose-templates前端用户用户

我有表格添加用户:

http://localhost/user/new

图片:http://img692.imageshack.us/img692/7726/znew.png

我想从模块附加添加此表单输入 new ,并将多个复选框的sfWidgetFormDoctrineChoice更改为。 我该怎么做?

THX!

1 个答案:

答案 0 :(得分:1)

sfWidgetFormDoctrineChoice 有一个名为'expanded'的选项,如果它为true,则会显示带复选框的选项(选中this example from the symfony's Jobeet)。

在你的UserForm.class.php中你必须放这样的东西(检查你的BaseUserForm.class.php)

<!-- lib/form/doctrine/UserForm.class.php -->
...
public function configure(){

    $this->setWidget('groups_list', new sfWidgetFormDoctrineChoice(array(
              'multiple' => true, 
              'model' => 'Group', //check that on your base
              'expanded' => true, //set checkboxs
    )));

}
...