Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:55:35+00:00 2026-06-15T20:55:35+00:00

I am trying to validate data integrity via the special validation event. My Phalcon\Mvc\Collection

  • 0

I am trying to validate data integrity via the special validation event. My Phalcon\Mvc\Collection model implements the validation() method with some Phalcon\Mvc\Model\Validator validators. In my controller, I save() that model. If the save operation fails, I try to output the error messages via the getMessages() method of the model. In other words, I follow the examples supplied in the documentation http://docs.phalconphp.com/en/latest/reference/odm.html

However, I get an error that the getMessages() method does not exist. My Phalcon version is 0.7.0. I checked the API http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Collection.html, and it does not show a getMessages() method. I also ran a reflection test on the Phalcon\Mvc\Collection class, and that observation was confirmed.

The documentation also states that we can implement our own validators using Phalcon\Mvc\Collection\Validator. However, it appears that this class does not exist.

So, my questions are:

  1. How do I show the error messages that are a result of a validation?
  2. How do I create custom validators?
  3. Is Phalcon\Mvc\Model\Validator\Uniqueness validator NOSQL compatible?

Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:55:36+00:00Added an answer on June 15, 2026 at 8:55 pm

    You’re right the getMessages() method was missing in the implementation. For now you can add it to your model while it’s officially added to the C class:

    <?php
    
    class Users extends Phalcon\Mvc\Collection
    {
       public function getMessages()
       {
           return $this->_errorMessages;
       }
    }
    

    1- How do I show the error messages that are a result of a validation? Check above

    2- How do I create custom validators?

    A validator is a class that inherits from “Phalcon\Mvc\Model\Validator” and implements “Phalcon\Mvc\Model\ValidatorInterface”:

    <?php
    
    use Phalcon\Mvc\Model\Validator,
    Phalcon\Mvc\Model\ValidatorInterface;
    
    class HashValidator extends Validator implements ValidatorInterface
    {
    
        public function validate($record)
        {
            $fieldName = $this->getOption('field');
            if (!preg_match('/[a-z]+/', $fieldName) {           
                $this->appendMessage("The hash is not valid", $fieldName, "Hash");
                return false;
            }
            return true;
        }
    
    }
    

    If you don’t want to reuse the validator you can simply add a validation rule to the model:

    <?php
    
    use Phalcon\Mvc\Model\Message;
    
    class Users extends Phalcon\Mvc\Collection
    {
    
        public function validation()
        {
            if (!preg_match('/[a-z]+/', $this->password) {          
                $this->_errorMessages[] = new Message("The hash is not valid", "password", "Hash");
                return false;
            }
            return true;
        }
    
        public function getMessages()
        {
            return $this->_errorMessages;
        }
    
    }
    

    3- Is Phalcon\Mvc\Model\Validator\Uniqueness validator NOSQL compatible?
    This validator is only compatible with SQL models, however, you can create a validator to work with NoSQL collections this way:

    <?php
    
    use Phalcon\Mvc\Model\Validator,
    Phalcon\Mvc\Model\ValidatorInterface;
    
    class UniqueValidator extends Validator implements ValidatorInterface
    {
    
        public function validate($record)
        {
            $field = $this->getOption('field');
            if ($record->count(array("field" => $record->readAttribute($field)))) {
                $this->appendMessage("The ".$field." must be unique", $fieldName, "Unique");
                return false;
            }
            return true;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to validate some form data before adding it to a database however
I'm been trying to validate Data in a Flex TextFiled, and I've encountered some
I'm trying to validate data in an imported csv file with Symfony2's validation component
I'm trying to figure out the best way to validate data within a MVC
I am trying to validate some XML via lxml and an xsd (ogckml22.xsd). This
I'm trying to validate some data in a CSV file I'm parsing through. The
I'm trying to validate some POST data. One of the validations I need to
I was trying to validate my User model data and I came upon this
I'm trying to validate data passing between client/server for a location-based application and I
While trying to validate form data on my page i get the following error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.