[英]Symfony2 load settings from database
I have a db table (doctrine entity) that I use to store some editable settings for my app, like page title, maintenance mode (on/off), and some other things.. 我有一个db表(doctrine实体),我用它来存储我的应用程序的一些可编辑设置,如页面标题,维护模式(开/关),以及其他一些东西..
I can load the settings normally using the entity manager and repositories, but I think that's not the best solution... 我可以使用实体管理器和存储库正常加载设置,但我认为这不是最好的解决方案......
My questions are: - can I load the settings only once at some kernel event and then access them the same way I access any other setting saved in yml config files.. 我的问题是: - 我可以在某个内核事件中仅加载一次设置,然后以与访问yml配置文件中保存的任何其他设置相同的方式访问它们。
LiipDoctrineCacheBundle provides a service wrapper around Doctrine's common Cache ( documentation ) that allows you to use several cache drivers like filesystem, apc, memcache, ... LiipDoctrineCacheBundle提供了一个围绕Doctrine的通用Cache( 文档 )的服务包装器,允许您使用多个缓存驱动程序,如filesystem,apc,memcache,...
I would recommend loading your generic container-parameters/settings (like maintainance mode,...) from database in a bundle-extension or a compiler-pass . 我建议在bundle-extension或compiler-pass中从数据库加载通用容器参数/设置(如维护模式......)。
route-specific settings (like page title, ...) could be loaded in a kernel event listener . 特定于路由的设置(如页面标题,...)可以加载到内核事件侦听器中 。 You can find a list of kernel events here . 您可以在此处找到内核事件列表。
update/invalidate their cache using a doctrine postUpdate/postPersist/postRemove listener . 使用doctrine postUpdate / postPersist / postRemove 侦听器更新/使其缓存无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.