Module :
public function getServiceConfig() {
return array(
'factories' => array(
// 'user' table-------------------------------------
'Album\Model\AlbumTable\dbtable=user' => function($sm) {
$tableGateway = $sm->get('UserTableGateway');
$table = new SignupTable($tableGateway);
return $table;
},
'UserTableGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Signup());
return new TableGateway('user', $dbAdapter, null, $resultSetPrototype);
},
),
);
}
Now how can I call my ‘dbadapter’ in anywhere in the model while I need it for
new \Zend\Validator\Db\RecordExists(
array(
'table' => 'user',
'field' => 'username',
'adapter' => $dbadapter
)
)
please tell me the way to call adapter in anywhere.
-thanks.
Edit :
I followed this 'Get default zend db adapter in table model' thread and did the following in my ‘model’,
<?php
namespace Application\Model;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
use Zend\Validator;
class Signup implements InputFilterAwareInterface {
public $username;
protected $inputFilter;
protected $serviceLocator;
protected $dbAdapter;
public function getServiceLocator() {
return $this->serviceLocator;
}
public function setServiceLocator(Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) {
$this->serviceLocator = $serviceLocator;
return $this;
}
public function exchangeArray($data) {
$this->username = (!empty($data['username'])) ? $data['username'] : null;
$this->password = (!empty($data['password'])) ? $data['password'] : null;
$this->email = (!empty($data['email'])) ? $data['email'] : null;
}
public function getArrayCopy() {
return get_object_vars($this);
}
public function setInputFilter(InputFilterInterface $inputFilter) {
throw new \Exception("Not used");
}
public function getInputFilter() {
$this->$dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$inputFilter->add(array(
'name' => 'username',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'NotEmpty',
'options' => array(
'messages' => array(
\Zend\Validator\NotEmpty::IS_EMPTY => 'Username required',
),
),
),
new \Zend\Validator\Db\RecordExists(
array(
'table' => 'user',
'field' => 'username',
'adapter' => $this->dbAdapter,
)
)
),
));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
}
but I got this error,
Fatal error: Call to a member function get() on a non-object in F:\xampp\htdocs\zendtest\module\Application\src\Application\Model\Signup.php on line 41
Why is that ?
I made it like the following,
Module :
Controller :
Model :