1) MembershipMapper:在此处实现您的查询,返回实体数组(查看 ZfcBase\Mapper\AbstractDbMapper 作为基类)
function getGroupsForMember($member, $access = null)
function getMembersForGroup($group, $access = null)
2)MembershipServive:在getServiceConfig 下的Module.php 中,将此服务添加到服务管理器。使用闭包创建一个新的 MembershipService 并将 MembershipMapper 注入其中。组/成员函数可能只是映射器的代理。
function setMembershipMapper($membershipMapper)
function getMembershipMapper()
function getGroupsForMember($member, $access = null)
function getMembersForGroup($group, $access = null)
3)控制器:将您的 MembershipService 注入到您的控制器中(您可以按照与使用闭包创建服务相同的方式执行此操作)。然后调用服务上的方法。
在服务/控制器管理器中创建服务/映射器/控制器的示例(在 Module.php 中)
public function getServiceConfig()
{
return array(
'factories' => array(
'MembershipService' => function (Zend\ServiceManager\ServiceManager $sm) {
$service = new YourNS\Service\Membership();
$service->setMembershipMapper($sm->get('MembershipMapper'));
return $service;
},
'MembershipMapper' => function ($sm) {
$mapper = new \YourNS\Mapper\Membership();
return $mapper;
},
);
}
public function getControllerConfig()
{
return array(
'factories' => array(
'YourNS\Controller\Something' => function (Zend\Mvc\Controller\ControllerManager $cm) {
$controller = new YourNS\Controller\Something();
$controller->setMembershipService($cm->getServiceLocator()->get('MembershipService'));
return $controller;
},
}