首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

#symfony

基于 MVC 架构的 PHP 框架

赛门铁克客户端安装错误?

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类,这也使控制器更薄,并且更好地将其从模型中抽象出来。... 展开详请
领券