我試圖顯示從數據庫的字段名稱用於表頭中顯示在管理部分提出的樹枝!字段名稱表
我有我的數據庫這樣一個
id | Gram | Height | Kilos |
1 | 27.1 | 126 cm | 29 kg |
,我想要得到的字段名「革蘭氏陰性,身高等」,並使其爲表頭,我打算做一個翻譯此類似英語到日本等等,「問題是如何獲取數據字段名稱並將其顯示爲文本的任何建議」,請提前致謝!
代碼控制器
/**
* @Route("/ingredients/header-translation", name = "z_recipe_header_translation")
* @Template("NutritionMainBundle:Admin\create\recipe\ingredients:translate-headers.html.twig")
*/
public function headerTranslationAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$nutrients = $em->getRepository("NutritionAdminBundle:NutritionValue")->findAll();
return array(
'header' => $nutrients
);
}
嫩枝代碼
<table class="table" style="width:100%;">
<thead>
<tr>
<th>header</th>
{% for ii in 1..9 %}
<th>language {{ii}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for i in 1..10 %}
<tr>
<td>header label {{i}}</td>
{% for ii in 1..9 %}
<td><input type="text"/></td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
哦,這是一個重複的問題,所以我們對此深感抱歉,我只會讓它作爲一個例子,下面的代碼將是我的最終答案,感謝您的幫助!
控制器代碼:
/**
* @Route("/ingredients/header-translation", name = "z_recipe_header_translation")
* @Template("NutritionMainBundle:Admin\create\recipe\ingredients:translate-headers.html.twig")
*/
public function headerTranslationAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$NutritionValueField = $em->getClassMetadata('NutritionAdminBundle:NutritionValue')->getFieldNames();
$languages = $em->getRepository("NutritionLanguageBundle:Language")->findAll();
$form = $this->createForm(new NutritionValueType());
$form->handleRequest($request);
return array(
'header' => $NutritionValueField,
'languages' => $languages,
'form' => $form->createView()
);
}
對於我的小枝顯示
<table class="table" style="width:100%;">
<thead>
<tr>
<th>header</th>
{% for languages in languages %}
<th>{{languages.langLabel}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for header in header %}
<tr>
{% if header == 'NDB_NO'%}
{#do nothing#}
{% else %}
<td>{{ header|replace({'_':' '}) }}</td>
{% for languages in languages %}
<td><input id="{{header}}_{{ languages.id }}" type="text" value="{{header|replace({'_':' '})}}"/> </td>
{% endfor %}
{% endif %}
</tr>
{% endfor %}
</t
體>
顯示代碼。沒有看到你在做什麼很難幫助你。 –