My goal is to select distinct records from database table, create array and send it as set of option to select type of form element and also i will need to use same data in form validation in haystack (data same as in options of form element) I thought i will be able to achieve this by creating factory which will return already existing adapter in factories
'adapter' => function($sm) {
$dbAdapter= $sm->get('Zend\Db\Adapter\Adapter');
return $dbAdapter ;
},
and after in forms and validator classes i planed to use service manager to get this adapter for sql query creation
/*protected $form;*/
protected $adapter;
public function getAdapter()
{
if (!$this->adapter) {
$this->adapter = $this->getServiceLocator()
->get('adapter');
}
return $this->adapter;
}
public function getDistinct(){
$sql = "SELECT DISTINCT (lw_folders.f_name), lw_folders.f_id FROM lw_folders INNER JOIN lw_links ON lw_folders.f_id = lw_links.f_id";
return $resultSet = $this->adapter->query($sql);}
But i get a lot of errors, one of them i saying that getServiceLocator() is not found in this form class.
Is my thoughts about usage right? Is there any other way to use custom query to get need records and use them in form class? Thanks for your time!