腾讯云
开发者社区
文档
建议反馈
控制台
登录/注册
首页
学习
活动
专区
工具
TVP
最新优惠活动
文章/答案/技术大牛
搜索
搜索
关闭
发布
精选内容/技术社群/优惠产品,
尽在小程序
立即前往
首页
标签
symfony
#
symfony
基于 MVC 架构的 PHP 框架
关注
专栏文章
(73)
技术视频
(3)
互动问答
(2.9K)
赛门铁克客户端安装错误?
0
回答
symfony
、
客户端
、
系统
Symfony最佳实践。查询应该在存储库中还是在服务中?
2
回答
symfony
狼宝珏
你可以在中间做点什么。 定义服务: blog.post_manager: class: Acme\BlogBundle\Entity\Manager\PostManager arguments: em: "@doctrine.orm.entity_manager" class: Acme\BlogBundle\Entity\Post 然后创建Manager类: use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; class PostManager { protected $em; protected $repo; protected $class; public function __construct(EntityManager $em, $class) { $this->em = $em; $this->class = $class; $this->repo = $em->getRepository($class); } public function get($id) { return $this->repo->findById($id); } } 这样,你仍然可以将查询保留在存储库中,同时允许通过管理器服务重用代码,在任何控制器中都可以这样使用: $this->container->get('blog.post_manager')->get(1); 由于服务负责将类和实体管理器注入Manager类,这也使控制器更薄,并且更好地将其从模型中抽象出来。...
展开详请
赞
0
收藏
0
评论
0
分享
你可以在中间做点什么。 定义服务: blog.post_manager: class: Acme\BlogBundle\Entity\Manager\PostManager arguments: em: "@doctrine.orm.entity_manager" class: Acme\BlogBundle\Entity\Post 然后创建Manager类: use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; class PostManager { protected $em; protected $repo; protected $class; public function __construct(EntityManager $em, $class) { $this->em = $em; $this->class = $class; $this->repo = $em->getRepository($class); } public function get($id) { return $this->repo->findById($id); } } 这样,你仍然可以将查询保留在存储库中,同时允许通过管理器服务重用代码,在任何控制器中都可以这样使用: $this->container->get('blog.post_manager')->get(1); 由于服务负责将类和实体管理器注入Manager类,这也使控制器更薄,并且更好地将其从模型中抽象出来。
相关
产品
基于 MVC 架构的 PHP 框架
热门
专栏
PhpZendo
71 文章
17 订阅
恩蓝脚本
12.6K 文章
90 订阅
网管叨bi叨
276 文章
34 订阅
林德熙的博客
2.1K 文章
61 订阅
程序员的知识天地
633 文章
52 订阅
领券