유효성 검사 클래스에서 ServiceLocator를 얻고 싶습니다. 컨트롤러 인스턴스에서 가져 왔지만 null을 반환합니다.젠드 프레임 워크 2 : 유효성 검사 클래스에서 ServiceLocator를 얻는 방법
MyValidation.php
namespace Register\Validator;
use Zend\Validator\AbstractValidator;
use Register\Controller\RegisterController;
class MyValidation extends AbstractValidator {
/*
code...
*/
function isValid($value)
{
$controller = new RegisterController();
$sm = $controller->getServiceLocator();
$tableGateway = $sm->get('Register\Model\RegisterTable');
$tableGateway->myValidationMethod($value);
}
}
Module.php
public function getServiceConfig()
{
return array(
'factories' => array(
'Register\Model\RegisterTable' => function($sm) {
$tableGateway = $sm->get('RegisterTableGateway');
$table = new RegisterTable($tableGateway);
return $table;
},
'RegisterTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new RegisterUser());
return new TableGateway('table-name', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
하지만 치명적인 오류 : 적절한 방법은 무엇 개체가 아닌
에() 멤버 함수를 얻기 위해 전화 모델 클래스에서 ServiceLocator를 얻으려면?