2

What's the best and most efficient way to get some data from one entity and display it on every page? I'm using twig and doctrine.

I have an entity and database table which is only ever going to have one instance. It has things like company name etc. It's essentially configuration stuff so I know a config file is more efficient but I want it to be editable by an admin user.

I guess I'm asking two questions. Where do I put the code to retrieve the entity on every request and how do I get the data into my top level twig template?

Thanks

4

2 に答える 2

3

コントローラーを埋め込む必要があります。

ある時点で、このようなものに対してキャッシングを行うことも必要になるでしょう。

于 2012-09-13T04:57:40.430 に答える
1

実際の質問に対する答えではありませんが、同じ問題を解決すると思います。SonataBlockBundleを使用して、特定の編集可能なブロックをフッターにレンダリングしています。住所、会社名などのフィールドを持つ実際の単一のエンティティは必要ないと思います。コンテンツ ブロックを作成してその中に HTML を配置するだけで十分な場合があるため、著作権などのコンテンツをより柔軟に追加できます。似たような。

BlockBundle の実装はコントローラーのレンダリングよりも少し難しいため、このアプローチも大変な作業になる可能性がありますが、他の多くのことにも使用できるため、検討する価値があるかもしれません。

于 2012-09-13T07:56:56.873 に答える