D
D
Dmitry2014-10-21 14:26:33
Zend Framework
Dmitry, 2014-10-21 14:26:33

How to check if a value exists in the database (zend 2)?

Essence: you need to check for the presence in the database of news with the entered URL.
At the moment the solution is something like:

public function checkUrl($url) {
        if ($this->getNewsTable()->getItemByURL($url)) {
            return true;
        } else {
            return false;
        }
    }

I would like to ask how to do this with the Db\RecordExists or Db\NoRecordExists validator? I tried to create an instance of the Zend\Validator\Db\RecordExists class (according to the manual) - nothing happened, the application crashes (blank screen).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shirshov Alexander, 2014-10-22
@another_dream

Give an example of the code that worked for you, there should be no problems with RecordExists.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question