symfony - Field's Name Table -
this question has answer here:
i trying display field name database used in table header displayed in twig admin section propose!
i have database 1
id | gram | height | kilos | 1 | 27.1 | 126 cm | 29 kg |
and want field name "gram, height etc" , make table header, going make translation english japanese , on, "the problem how data field name , display text advice on", thank in advance!
code controller
/** * @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 ); }
twig code
<table class="table" style="width:100%;"> <thead> <tr> <th>header</th> {% ii in 1..9 %} <th>language {{ii}}</th> {% endfor %} </tr> </thead> <tbody> {% in 1..10 %} <tr> <td>header label {{i}}</td> {% ii in 1..9 %} <td><input type="text"/></td> {% endfor %} </tr> {% endfor %} </tbody> </table>
oh duplicate question sorry that, i'll make example, code below final answer, thank help!
controller code:
/** * @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() ); }
for twigs display
<table class="table" style="width:100%;"> <thead> <tr> <th>header</th> {% languages in languages %} <th>{{languages.langlabel}}</th> {% endfor %} </tr> </thead> <tbody> {% header in header %} <tr> {% if header == 'ndb_no'%} {#do nothing#} {% else %} <td>{{ header|replace({'_':' '}) }}</td> {% languages in languages %} <td><input id="{{header}}_{{ languages.id }}" type="text" value="{{header|replace({'_':' '})}}"/> </td> {% endfor %} {% endif %} </tr> {% endfor %} </t
body>
use database information schema. select `column_name` `information_schema`.`columns` `table_schema`='databasename' , `table_name`='tablename';
wiki
Comments
Post a Comment