<tfoot id='P0R4N'></tfoot>

    <legend id='P0R4N'><style id='P0R4N'><dir id='P0R4N'><q id='P0R4N'></q></dir></style></legend>

      <i id='P0R4N'><tr id='P0R4N'><dt id='P0R4N'><q id='P0R4N'><span id='P0R4N'><b id='P0R4N'><form id='P0R4N'><ins id='P0R4N'></ins><ul id='P0R4N'></ul><sub id='P0R4N'></sub></form><legend id='P0R4N'></legend><bdo id='P0R4N'><pre id='P0R4N'><center id='P0R4N'></center></pre></bdo></b><th id='P0R4N'></th></span></q></dt></tr></i><div id='P0R4N'><tfoot id='P0R4N'></tfoot><dl id='P0R4N'><fieldset id='P0R4N'></fieldset></dl></div>
    1. <small id='P0R4N'></small><noframes id='P0R4N'>

      • <bdo id='P0R4N'></bdo><ul id='P0R4N'></ul>

      Symfony 生成器形式、学说和 M:N 关系

      Symfony Generator Forms, Doctrine, and M:N Relationships(Symfony 生成器形式、学说和 M:N 关系)

        <tfoot id='kShSu'></tfoot>

          <legend id='kShSu'><style id='kShSu'><dir id='kShSu'><q id='kShSu'></q></dir></style></legend>
            <tbody id='kShSu'></tbody>
          <i id='kShSu'><tr id='kShSu'><dt id='kShSu'><q id='kShSu'><span id='kShSu'><b id='kShSu'><form id='kShSu'><ins id='kShSu'></ins><ul id='kShSu'></ul><sub id='kShSu'></sub></form><legend id='kShSu'></legend><bdo id='kShSu'><pre id='kShSu'><center id='kShSu'></center></pre></bdo></b><th id='kShSu'></th></span></q></dt></tr></i><div id='kShSu'><tfoot id='kShSu'></tfoot><dl id='kShSu'><fieldset id='kShSu'></fieldset></dl></div>
          • <bdo id='kShSu'></bdo><ul id='kShSu'></ul>
          • <small id='kShSu'></small><noframes id='kShSu'>

                本文介绍了Symfony 生成器形式、学说和 M:N 关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个基本的 M:N 设置,其中包含三个表:候选、位置和候选位置.

                I have a basic M:N setup with three tables: candidate, position, and candidate_position.

                这是来自 MySQL Workbench 的 ERD 的屏幕截图

                Here's a screenshot of the ERD from MySQL Workbench

                现在,让我们继续讨论表单.在 symfony 生成器的默认世界中,这三个表都有一个单独的 CRUD 接口.但是,我不想为 candidate_position 提供 CRUD 接口.

                Now, moving on from that let's talk about forms. In the default world of symfony generator, you'd have a separate CRUD interface for all three of these tables. However, I don't want to have a CRUD interface for candidate_position.

                我想要的是,候选界面的创建和编辑操作包含一个多选字段(选择列表、复选框数组等),它将创建候选位置记录作为候选操作的一部分.

                What I want, is for the create and edit actions of the Candidate interface to contain a multi-choice field (select list, checkbox array, whatever) that would create the CandidatePosition records as part of the Candidate actions.

                进入代码

                config/doctrine/schema.yml (注意:不是整个schema.yml,只是这里讨论的表)

                ---
                detect_relations: true
                options:
                  type: InnoDB
                
                candidate:
                  columns:
                    id:
                      type: integer(4)
                      primary: true
                      unsigned: true
                      notnull: true
                      autoincrement: true
                    first_name:
                      type: string(45)
                      notnull: true
                    last_name:
                      type: string(45)
                      notnull: true
                    created_at:
                      type: integer(4)
                      unsigned: true
                  relations:
                    Positions:
                      class: Position
                      refClass: CandidatePosition
                      local: candidate_id
                      foreign: position_id
                
                position:
                  columns:
                    id:
                      type: integer(4)
                      primary: true
                      unsigned: true
                      notnull: true
                      autoincrement: true
                    name:
                      type: string(45)
                  relations:
                    Candidates:
                      class: Candidate
                      refClass: CandidatePosition
                      local: position_id
                      foreign: candidate_id
                
                
                candidatePosition:
                  tableName: candidate_position
                  columns:
                    candidate_id:
                      type: integer(4)
                      primary: true
                      unsigned: true
                      notnull: true
                    position_id:
                      type: integer(4)
                      primary: true
                      unsigned: true
                      notnull: true
                  indexes:
                    fk_candidate_position_candidate1:
                      fields: [candidate_id]
                    fk_candidate_position_position1:
                      fields: [position_id]
                

                apps/backend/modules/candidate/config/generator.yml

                generator:
                  class: sfDoctrineGenerator
                  param:
                    model_class:           Candidate
                    theme:                 admin
                    non_verbose_templates: true
                    with_show:             false
                    singular:              ~
                    plural:                ~
                    route_prefix:          candidate
                    with_doctrine_route:   true
                    actions_base_class:    sfActions
                
                    config:
                      actions: ~
                      fields:  
                        first_name: { label: First Name }
                        last_name:  { label: Last Name }
                        created_at: { label: Created On }
                        candidate_positions:  {label: Positions}
                      list:    
                        sort:  [last_name, asc]
                      filter:  ~
                      form:    
                        display:
                          "User": [first_name, last_name]
                          "Applying For": [candidate_positions]
                        fields :
                          hide:  [created_at]
                      edit:    ~
                      new:     ~
                

                lib/form/doctrine/candidateForm.class.php

                class candidateForm extends BasecandidateForm
                {
                  public function configure()
                  {
                    unset( $this['created_at'] );
                
                    $this->widgetSchema['candidate_positions'] = new sfWidgetFormDoctrineChoice(
                      array( 'multiple' => true, 'model' => 'Position', 'renderer_class' => 'sfWidgetFormSelectCheckbox' )
                    );
                
                    $this->validatorSchema['candidate_positions'] = new sfValidatorDoctrineChoice(
                      array( 'multiple' => true, 'model' => 'Position', 'min' => 1 )
                    );
                  }
                }
                

                这一切都有效,除了实际保存数据时.这就是我卡住的地方.

                This all works, except when it comes to actually saving the data. This is the point where I get stuck.

                我显然需要做一些事情来创建/编辑/删除 CandidatePosition 记录,但我不确定从哪里开始工作.在 candidateActions 中?覆盖 Basecandidate::save()?

                I clearly need to do something to create/edit/delete the CandidatePosition records, but I'm not sure where to start working. In candidateActions? Override Basecandidate::save()?

                如果您可能需要查看任何其他数据,请告诉我.

                Let me know if there's any other data you might need to see.

                • PHP 5.2.x
                • symfony 1.4.3

                推荐答案

                大约 10 个月前,我在连接表中的 M:N 关系和元数据方面遇到了类似的问题.

                About 10 month ago I had similar trouble with M:N relationships and meta-data in the join table.

                我发现 melikedev 的那些博客条目非常有用!这与您的用例并不完全相同,但它可能会给您一些提示:

                I found those blog entries of melikedev very useful! This is not exactly the same as your use case, but it might give you some hints:

                http:///melikedev.com/2009/12/09/symfony-w-doctrine-saving-many-to-many-mm-relationships/

                http://melikedev.com/2009/12/06/symfony-sfformextraplugin-select-double-list-maintain-order/

                http://melikedev.com/2010/04/06/symfony-saving-metadata-during-form-save-sort-ids/

                这篇关于Symfony 生成器形式、学说和 M:N 关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
              • <i id='8UkNd'><tr id='8UkNd'><dt id='8UkNd'><q id='8UkNd'><span id='8UkNd'><b id='8UkNd'><form id='8UkNd'><ins id='8UkNd'></ins><ul id='8UkNd'></ul><sub id='8UkNd'></sub></form><legend id='8UkNd'></legend><bdo id='8UkNd'><pre id='8UkNd'><center id='8UkNd'></center></pre></bdo></b><th id='8UkNd'></th></span></q></dt></tr></i><div id='8UkNd'><tfoot id='8UkNd'></tfoot><dl id='8UkNd'><fieldset id='8UkNd'></fieldset></dl></div>

              • <small id='8UkNd'></small><noframes id='8UkNd'>

                <tfoot id='8UkNd'></tfoot>

                  <legend id='8UkNd'><style id='8UkNd'><dir id='8UkNd'><q id='8UkNd'></q></dir></style></legend>

                    <tbody id='8UkNd'></tbody>

                          <bdo id='8UkNd'></bdo><ul id='8UkNd'></ul>