Удаление заголовков таблиц из embedRelation()

Я использовал embedRelation() для добавления другой формы в пользовательскую форму sfGuard. Он работает правильно, я просто пытаюсь стилизовать его, чтобы он соответствовал текущей форме.

Это тянет форму в:

$this->embedRelation('Profile');

но он добавляет некоторые дополнительные элементы html, которые я хотел бы удалить:

<div class="form_row">
 Profile 
 <table>
  <tbody><tr>
  <th><label for="sf_guard_user_Profile_department_title">Department</label></th>
  <td><input type="text" name="sf_guard_user[Profile][department_title]" value="Graphic Design" id="sf_guard_user_Profile_department_title"><input type="hidden" name="sf_guard_user[Profile][id]" value="2" id="sf_guard_user_Profile_id">
<input type="hidden" name="sf_guard_user[Profile][sf_guard_user_id]" value="10" id="sf_guard_user_Profile_sf_guard_user_id"></td>
</tr>
</tbody></table> <input type="hidden" name="sf_guard_user[id]" value="10" id="sf_guard_user_id"> </div>

Как я могу удалить «Профиль»? Я также хотел бы, чтобы метка не была заключена в заголовок таблицы. Возможно ли это с помощью embedRelation?

ОБНОВЛЕНО Средство форматирования схемы:

sfWidgetFormSchemaFormatter удаляет элементы таблицы из встроенной формы. Я до сих пор не могу понять, как избавиться от «Профиля». Я добавил sfWidgetFormSchemaFormatter

sfWidgetFormSchemaFormatterAc2009.class.php

    <?php 

    class sfWidgetFormSchemaFormatterAc2009 extends sfWidgetFormSchemaFormatter
    {
      protected
        $rowFormat       = "%error% \n %label% \n %field%
                            %help% %hidden_fields%\n",
        $errorRowFormat  = "<div>%errors%</div>",
        $helpFormat      = '<div class="form_help">%help%</div>',
        $decoratorFormat = "%content%";

        public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
        {
          $row = parent::formatRow(
            $label,
            $field,
            $errors,
            $help,
            $hiddenFields
          );

          return strtr($row, array(
            '%row_class%' => (count($errors) > 0) ? ' form_row_error' : '',
          ));
        }

        public function generateLabel($name, $attributes = array())
      {
        $labelName = $this->generateLabelName($name);

        if (false === $labelName)
        {
          return '';
        }

        if (!isset($attributes['for']))
        {
          $attributes['for'] = $this->widgetSchema->generateId($this->widgetSchema->generateName($name));
        }

        // widget name are usually in lower case. Only embed form have the first character in upper case

        var_dump($name);

        if (preg_match('/^[A-Z]/', $name))
        {
          // do not display label
          return ;
        }
        else
        {
          return $this->widgetSchema->renderContentTag('label', $labelName, $attributes);
        }
      }
    }

HTML:

<div class="form_row">
 Profile 
 <div>

 <label for="sf_guard_user_Profile_department_title">Department</label> 
 <input class=" text size-300" type="text" name="sf_guard_user[Profile][department_title]" value="Graphic Design" id="sf_guard_user_Profile_department_title">
                         <input type="hidden" name="sf_guard_user[Profile][id]" value="2" id="sf_guard_user_Profile_id">
</div> <input type="hidden" name="sf_guard_user[id]" value="10" id="sf_guard_user_id"> </div>

ОБНОВЛЕНИЕ 2:

Новая функция generateLabel($name, $attributes = array()) генерирует это вверху формы:

string(16) "department_title"

Профиль остается.

РЕШЕНО

Я смог выполнить это с помощью JQuery

Я добавил это в шаблон editSuccess.php:

<script>
var $body = $('.content-box');
var html = $body.html();
var newHtml = html.replace('Profile', '');
$body.html(newHtml);
</script>

person Carey Estes    schedule 18.06.2012    source источник
comment
Тот же вопрос здесь.   -  person j0k    schedule 20.06.2012


Ответы (2)


Я нашел обходной путь, который работает для меня. Немного странное решение.

Метка отображается с помощью generateLabel. Итак, если мы хотим скрыть метку, у нас есть только имя метки для создания условия.

В вашем пользовательском форматере:

  public function generateLabel($name, $attributes = array())
  {
    $labelName = $this->generateLabelName($name);

    if (false === $labelName)
    {
      return '';
    }

    if (!isset($attributes['for']))
    {
      $attributes['for'] = $this->widgetSchema->generateId($this->widgetSchema->generateName($name));
    }

    // widget name are usually in lower case. Only embed form have the first character in upper case
    if (preg_match('/^[A-Z]/', $name))
    {
      // do not display label
      return ;
    }
    else
    {
      return $this->widgetSchema->renderContentTag('label', $labelName, $attributes);
    }
  }
person j0k    schedule 22.06.2012
comment
Эта функция должна идти в расширенном SchemaFormatter правильно? sfWidgetFormSchemaFormatterAc2009.class.php (класс sfWidgetFormSchemaFormatterAc2009 расширяет sfWidgetFormSchemaFormatter) - person Carey Estes; 25.06.2012
comment
Это не делает меня :( Я обновил schemaformatter.class в сообщении выше. Может быть, я что-то не так разместил. - person Carey Estes; 25.06.2012
comment
Нет, расположение правильное. Не могли бы вы var_dump($name); перед if (preg_match добавить его к вопросу? - person j0k; 25.06.2012
comment
добавил это к вопросу. Все еще нет в тестировании. - person Carey Estes; 25.06.2012
comment
Он отображает только один string(16) "department_title"? Теоретически он должен сбрасывать каждое имя поля. - person j0k; 25.06.2012
comment
Я смог решить другим способом, используя JQuery, но это было очень полезно - person Carey Estes; 25.06.2012

Взгляните на sfWidgetFormSchemaFormatter — также описан здесь

person Del Pedro    schedule 20.06.2012