I just update my ZF2 to V2.1.4 so that I can use the init method of the Zend\Form class for inject the ServiceLocator into FieldSet as explains the Zend documentation.
I have in the Global.php and Module.php files a definitions of Database driver and a service ,how also explains the documentation. This service works ok in all project.
This is my Fieldset Code:
class UserFieldset extends Fieldset implements ServiceLocatorAwareInterface{
protected $serviceLocator;
public function setServiceLocator(ServiceLocatorInterface $sl) {
$this->serviceLocator = $sl;
}
public function getServiceLocator() {
return $this->serviceLocator;
}
public function init() {
var_dump($this->serviceLocator);
}
public function __construct() {
.........
}
}
My problem is the follow:
Inside of UserFieldset::init() method, $this->serviceLocator isn't instance of Zend\ServiceManager\ServiceManager like when get the service from controller. The instance is of Zend\Form\FormElementManager and using var_dump, see that it doesn't have any service of my Zend configuration.
How can I have a Zend\ServiceManager\ServiceManager instance inside the Fieldset using DI?
Please help me.