2012-06-18 2 views
1

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

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

$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?

ОБНОВЛЕНО Схема Formatter:

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> 

UPDATE 2:

Новая функция generateLabel ($ имя, $ атрибуты = массив ()) генерирует это в верхней части формы:

строка (16) "department_title"

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

ПОСТАНОВИЛИ

я смог acomplish это с помощью JQuery

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

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

тот же вопрос [здесь] (http://stackoverflow.com/questions/11119789/symfony-1-4-embedded-form-fields-at-the-same -indent). – j0k

ответ

1

Я нашел работу, которая работает для меня. Это немного странное решение.

Метка отображается с использованием 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); 
    } 
    } 
+0

Эта функция должна соответствовать правильной версии SchemaFormatter? sfWidgetFormSchemaFormatterAc2009.class.php (класс sfWidgetFormSchemaFormatterAc2009 расширяет sfWidgetFormSchemaFormatter) –

+0

Да, на том же уровне функции 'formatRow'. – j0k

+0

Это не делает меня из меня :(Я обновил schemaformatter.class в вышеупомянутом сообщении. Возможно, у меня что-то не так в размещении. –

1

Взгляните на sfWidgetFormSchemaFormatter - также описал here

Смежные вопросы