1
저는 Codeigiter와 Twig를 사용하고 있습니다. 데이터베이스의 데이터로 구성된 동적 선택 상자를 만들려고합니다. 여기Twig 배열에서 Twig 변수를 생성하십시오.
내가 그래서 무엇보다도 지금
// animals is $data['animals']=$this->loadmodel->some_function()
// animals passed from the controller ...
<select id="foo" class="form-control">
<option selected="true" >Animals</option>
{% for animal_key in animals %}
<option >
{{ animal_key ["animal_description"] }}
</option>
{% endfor %}
</select>
을하고있어 잘 작동 것입니다. 그러나 내가 그것을 역동적으로 만들고자한다면 어떨까요?
가의 배열을 설정 : 각 선택 상자는 컨트롤러에서 다른 방법에서 데이터를 얻을 -
내가 생각했던 어떤 // orders is $data['orders']=$this->loadmodel->some_function()
// orders passed from the controller ...
<select id="foo" class="form-control">
<option selected="true" >orders</option>
{% for order_key in orders%}
<option >
{{ order_key ["order_description"] }}
</option>
{% endfor %}
</select>
<select id="foo" class="form-control">
<option selected="true" >Animals</option>
{% for animal_key in animals %}
<option >
{{ animal_key ["animal_description"] }}
</option>
{% endfor %}
</select>
이 그런 짓을하는 것이었다 여기처럼 - 내가 다른 방법의 데이터가 있다고 가정 컨트롤러의 이름 :
{% set controller_names = ['animals','orders']%}
설정 컨트롤러의 배열 변수 습니 자신의 키 :
, {% set controller_vars =
['animals'=>'animal_description','orders'=>'order_description']%}
그런 다음 당신이 할 수있는
목 다음 attribute 기능을 사용 anks -하지만 작동하지 않습니다 ... 제발 확장 예제를 주실 수 있습니까? – RoyBarOn
안녕하세요 @RoyBarOn 죄송합니다. 예제에서 실수를했습니다. 속성 함수의 매개 변수를 뒤집습니다 (답변을 업데이트합니다). 시도해 볼 수 있습니까? – Matteo
죄송합니다 - 작동하지 않습니다 - 키와 값이 PHP 변수라는 것을 나뭇 가지에 "말하려고합니다."... – RoyBarOn