配列を返す関数からすべてのオプションを取得する選択(または選択肢)フィールドがあります。AdminクラスのSymfony Sonataで設定プールにアクセスするにはどうしたらいいですか?
これは選択フィールドを定義する行です。
->add('possibilities', 'choice', array('choices' => Crud::enumStatus()))
これはenumStatus関数です。私は上記で説明何
はpublic static function enumStatus()
{
return array(
'1' => 'Awaiting Approval',
'2' => 'Partly Approved',
'3' => 'Approved',
'4' => 'Disapproved',
'5' => 'Complete'
);
}
完璧に動作します。しかし、私が実際に望んでいることはうまくいかない。プリンシパルは同じままです。
これは私が望むものです。
->add('possibilities', 'choice', array('choices' => Crud::getUsers(array('Marketing', 'Human Resource Management'))))
上記と同じクラスの機能。
public function getUsers($roles)
{
$queryBuilder = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager('admin')
->createQueryBuilder();
$queryBuilder->select('u.id, u.name')
->from('Qi\Bss\BaseBundle\Entity\Admin\User', 'u')
->innerJoin('u.businessRoles', 'r')
->where('r.name IN (:roles)')
->setParameter('roles', $roles)
->orderby('u.name');
$result = $queryBuilder->getQuery()->getResult();
$users = array();
foreach ($result as $key => $value) {
$users[$value['id']] = $value['name'];
}
return $users;
}
エラー私が欲しいものをしよう。
は、クラス の "getConfigurationPool" "XX \ YYY \ QqqBundle \コントローラ\ OrderController" メソッドを呼び出そうとしました。
エラーメッセージに記載されているコントローラーは、 - > add()が2つの関数ではなく、自分のフォーム用のコントローラーです。
なぜ最初のものは動作しますが、2番目のものは動作しませんか?誰かがこれを私に説明してもらえますか? 1つの機能でstatic
と関係がありますか?そして、どうすればこの問題を解決できますか? configurationPoolとは何ですか、どのように取得しますか?
私はSonata Admin BundleとSymfonyを使用します。
申し訳ありませんが、最後に多すぎる質問をします。選択肢を修正し、getUsersメソッドとgetConfigurationPoolエラーから適切な情報を取得する方法について説明しましょう。 –
あなたの質問に「構成プールにアクセスする方法」というタイトルはありませんか? – pbenard
よかったです。それを変更します。 –