所以,我要做到以下幾點:學說的DBAL在Symfony2中與形式
我在/Form/Type/UserType.php
創建的窗體類我有一個表的狀態列表(表名爲「狀態」)。
我想在下拉菜單中顯示所有這些狀態。
我應該在類UserType中使用哪些代碼來顯示所有狀態?
我想:
$request = new Request;
$conn = $request->get('database_connection');
$states = $conn->fetchAll('SELECT state_code, state_name FROM states');
$builder->add('state', 'choice', array(
'choices' => $states,
'required' => false,
));
但給我一個錯誤。基本上,我想查詢表狀態中的所有狀態,並從所有這些狀態創建一個下拉菜單。