Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set db adapter to Validator RecordExists in Zend Framework 2
    text
    copied!<p>I'm trying to add validator RecordExists to my form but I get error 'no db adapter present'. How can I set db adapter to this validator? I use examples from skeleton application and I'm trying to do something like this (yes, I know that $dbAdapter is undefined :) I'm searching solution how to change this variable to db adapter resource ):</p> <pre><code>namespace Album\Model; use Zend\InputFilter\Factory as InputFactory; // &lt;-- Add this import use Zend\InputFilter\InputFilter; // &lt;-- Add this import use Zend\InputFilter\InputFilterAwareInterface; // &lt;-- Add this import use Zend\InputFilter\InputFilterInterface; // &lt;-- Add this import class Album implements InputFilterAwareInterface { public $id; public $artist; public $title; protected $inputFilter; // &lt;-- Add this variable public function exchangeArray($data) { $this-&gt;id = (isset($data['id'])) ? $data['id'] : null; $this-&gt;artist = (isset($data['artist'])) ? $data['artist'] : null; $this-&gt;title = (isset($data['title'])) ? $data['title'] : null; } // Add content to this method: public function setInputFilter(InputFilterInterface $inputFilter) { throw new \Exception("Not used"); } public function getInputFilter() { if (!$this-&gt;inputFilter) { $inputFilter = new InputFilter(); $factory = new InputFactory(); $inputFilter-&gt;add($factory-&gt;createInput(array( 'name' =&gt; 'id', 'required' =&gt; true, 'filters' =&gt; array( array('name' =&gt; 'Int'), ), 'validators' =&gt; array( array( 'name' =&gt; 'Db\RecordExists', 'options' =&gt; array( 'table' =&gt; 'album', 'field' =&gt; 'title', 'adapter' =&gt; $dbAdapter ), ), ), ))); $this-&gt;inputFilter = $inputFilter; } return $this-&gt;inputFilter; } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload