我收到以下错误
While attempting to create memberformmembernextpasswordchange(alias: Member\Form\member\NextPasswordChange) an invalid factory was registered for this instance type.
我创建了以下文件结构(包含表单,输入过滤器和服务的子目录),以便于长期维护,因为会员模块的每个部分都有如此多的内容:
[root@localhost src]$ find . -type d
.
./Member
./Member/Form
./Member/Form/member
./Member/Form/member/Factory
./Member/Controller
./Member/Controller/Factory
./Member/Service
./Member/Service/Form
./Member/Service/Form/Factory
./Member/Service/Factory
./Member/InputFilter
./Member/InputFilter/member
但我无法弄清楚如何“链接”子目录包含的文件。这甚至可能吗?
在module.config.php中我有
'form_elements' => [
'factories' => [
'Member\Form\member\NextPasswordChange' => 'Member\Form\member\Factory\NextPasswordChangeFactory',
],
],
'input_filters' => [
'invokables' => [
'Member\InputFilter\member\NextPasswordChange' => 'Member\InputFilter\member\NextPasswordChange',
]
],
'service_manager' => [
'factories' => [
'Member\Service\Member' => 'Member\Service\Factory\MemberFactory',
'Member\Service\Form\NextPasswordChange' => 'Member\Service\Form\Factory\NextPasswordChangeFactory',
]
],
在MemberControllerFactory中我有
/**
* @param ServiceLocatorInterface $serviceLocator
*
* @return MemberController
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/**
* @var \Zend\ServiceManager\ServiceLocatorAwareTrait $serviceLocator
*/
$sl = $serviceLocator->getServiceLocator();
/**
* @var \Member\Form\member\NextPasswordChange $formNextPasswordChange
*/
$formNextPasswordChange = $sl->get('FormElementManager')
->get('Member\Form\member\NextPasswordChange');
/**
* @var \Member\Service\Member $serviceMember
*/
$serviceMember = $sl->get('Member\Service\Member');
/**
* @var \Member\Service\Form\NextPasswordChange $serviceNextPasswordChange
*/
$serviceNextPasswordChange = $sl->get('Member\Service\Form\NextPasswordChange');
return new MemberController(
$formNextPasswordChange,
$serviceMember,
$serviceNextPasswordChange
);
}
MemberController的标题部分包含
namespace Member\Controller;
use Member\Form\member\NextPasswordChange as FormNextPasswordChange;
use Member\Service\Member as ServiceMember;
use Member\Service\Form\NextPasswordChange as ServiceNextPasswordChange;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
/**
* Class MemberController
*
* @package Member\Controller
*
* @method Request getRequest()
*/
class MemberController extends AbstractActionController
{
/**
* @var FormNextPasswordChange $formNextPasswordChange
*/
private $formNextPasswordChange;
/**
* @var ServiceMember $serviceMember
*/
private $serviceMember;
/**
* @var ServiceNextPasswordChange $serviceNextPasswordChange
*/
private $serviceNextPasswordChange;
/**
* @param FormNextPasswordChange $formNextPasswordChange
* @param ServiceMember $serviceMember
*/
public function __construct(
FormNextPasswordChange $formNextPasswordChange,
ServiceMember $serviceMember,
ServiceNextPasswordChange $serviceNextPasswordChange
)
{
$this->formNextPasswordChange = $formNextPasswordChange;
$this->serviceMember = $serviceMember;
$this->serviceNextPasswordChange = $serviceNextPasswordChange;
}