【问题标题】:default form in Symfony - add new input and change choiceSymfony 中的默认表单 - 添加新输入并更改选择
【发布时间】:2011-06-24 17:54:37
【问题描述】:

我的 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 学说:生成模块 --with-show --non-verbose-templates 前端用户用户

我有表单添加用户:

http://localhost/user/new

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

我想为这个表单添加 new 从模块 additional 并更改 sfWidgetFormDoctrineChoice 为多个复选框。 我该怎么做呢?

谢谢!

【问题讨论】:

  • 这个问题和你之前的问题表明你缺少基本的 Symfony 知识。通过Jobeet Tutorial。从长远来看,它将使您避免许多错误并节省您的时间。

标签: php symfony1 doctrine symfony-1.4


【解决方案1】:

sfWidgetFormDoctrineChoice 有一个名为 'expanded' 的选项,如果它为真,那么将显示带有复选框的选项(检查 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
    )));

}
...

【讨论】:

    猜你喜欢
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    • 2014-12-27
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    相关资源
    最近更新 更多