컨트롤러 전달 - 위대한 기능이며 위젯 개념을 만들었습니다. 그러나 기본적으로 비 자체 모듈의 컨트롤러를 디스패치 할 수는 없습니다. (또한 모든 콘트롤 구성을 피하기 위해)이 문제를 해결하려면, 나는 컨트롤러 constructon에 대한 abstaract_factory 추가 :Zend2 - 다른 모듈 컨트롤러를 전달하는 방법?
namespace Engine\Mvc\Controller;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class Autoloader implements AbstractFactoryInterface
{
public function canCreateServiceWithName(ServiceLocatorInterface $locator, $name, $requestedName)
{
return true;
}
public function createServiceWithName(ServiceLocatorInterface $locator, $name, $requestedName)
{
$class = ucfirst(str_replace('/', '\\', $requestedName)).'Controller';
if (!class_exists($class)){
return false;
}
return new $class;
}
}
/*In Module class*/
public function getControllerConfig()
{
return array(
'abstract_factories' => array(
'Engine\Mvc\Controller\Autoloader'
),
);
}
그것은 잘 작동합니다. 그러나 생성자 인수가없는 호출 가능한 컨트롤러에만 해당됩니다.
/*in zfc-user/module.config.php */
'controllers' => array(
'factories' => array(
'zfcuser' => 'ZfcUser\Factory\Controller\UserControllerFactory',
),
),
/*factory for controller*/
class UserControllerFactory implements FactoryInterface
{
/**
* Create controller
*
* @param ControllerManager $serviceLocator
* @return UserController
*/
public function createService(ServiceLocatorInterface $controllerManager)
{
/* @var ServiceLocatorInterface $serviceLocator */
$serviceLocator = $controllerManager->getServiceLocator();
$userService = $serviceLocator->get('zfcuser_user_service');
$registerForm = $serviceLocator->get('zfcuser_register_form');
$loginForm = $serviceLocator->get('zfcuser_login_form');
$options = $serviceLocator->get('zfcuser_module_options');
$controller = new UserController($userService, $options, $registerForm, $loginForm);
return $controller;
}
}
비뚤어진에서 - 내가 (예를 들어, 작곡가와 함께 설치 ZfcUser를) 변경할 수 없습니다, 모듈에서 컨트롤러를 포함 할 때 theese 컨트롤러가 아닌 호출 가능한 초기화를 가질 수 있기 때문에, 실패 할 수 있습니다 module1UserControllerFactory
ZfcUser 모듈을 볼 수 없다면, UserController가 모든 인수를 필요로하기 때문에 내 abstract_factory로 컨트롤러를 구성하려고 시도하고 오류가 발생합니다.
Zend\Mvc\Controller\Plugin\Service\ForwardFactory
을 스왑하여 해결할 수 있습니다. Forward를 "global"로 구성해야합니다. ControllerManager
. 그러나 확실하지 않습니다. "글로벌"ControllerManager
은 Zend2에 존재합니다.
질문 :
- 가되어 ControllerManager, 어떻게 내가이 ServiceManager의에서 얻을 수있는 글로벌?
- 컨트롤러 플러그인을 사용하는 다른 방법으로 비자가 모듈 컨트롤러 (비 자체 모듈 컨트롤러 구성으로 컨트롤러 구성시)?
은 [링크]를 참조하십시오 (http://stackoverflow.com/questions/14180839/is-it-possible-to-forward-data-to-another-controller -action-in-zend-2) –