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

  • Home
  • SEARCH
  • 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 9020445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:01:07+00:00 2026-06-16T05:01:07+00:00

The validation on Kohana ORM is done using rules function rules() { return array(

  • 0

The validation on Kohana ORM is done using rules

function rules()
{
  return array(
    'username' => array(
      array('not_empty'),
      array(array($this, 'availability')),
    )
  );
}

I’m struggling to validate a JSON encoded column using $_serialize_columns.

class Model_Admin extends ORM {
  protected $_belongs_to = array();
  protected $_has_many = array(
    'plans' => array(),
    'groups' => array(),
    'transactions' => array(),
    'logins' => array()
  );

  protected $_serialize_columns = array('data');

  /**
   * @param array $data
   * @param Validation $validation
   *
   * @return bool
   */
  public function data($data, $validation)
  {
     return 
       Validation::factory(json_decode($data, TRUE))
       // ... rules ...
       ->check();
  }

  public function rules()
  {
     return array(
       'data' => array(
         array(array($this, 'data'), array(':value',':validation')
       )
     );
  }
}

the array that gets encoded is:

array(
  'name' => '',
  'address' => '',
  'phone' => '',
  'postalcode' => ''
);

the data method receives the json encoded data, because the ORM runs the filters before doing the validation, so I need to convert it back to an associative array, then create a new validation object to check specifically for the content of that array. Because I can’t merge Validation rules from another Validation instance

  • 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-16T05:01:08+00:00Added an answer on June 16, 2026 at 5:01 am

    Updated Answer

    The use of a second validation object is necessary since save() causes the internal model validation object to be checked. This means that rules added to the validation object being checked from a validation rule will be ignored (Validation->check() imports the rules into local scope before looping).

    Since the data itself is technically another object (in the sense of object relationships, it has its own dataset that needs validation) the ideal solution would be to find a way to create a real model that saves the data.

    There are numerous other benefits to saving data with proper database column definitions, not least if you need to perform data property lookups, make in-situ changes etc. (which would otherwise require unserializing the data column, potetnailly in all rows).

    There are some alternatives, but they feel like kludges to me:

    1. Create a model that represents the data object and add rules to it, using check() to validate the data (problem: will require a lot of maintenance, no real-world table means columns must be manually defined).

    2. Set the data as real columns in the Admin model, and use a filter that will convert it into the data column on set (problem: again, must manually define the columns and exclude the additional columns from the save operation).

    I hope this is of some use.

    Original Answer

    The Kohana ORM save() method permits the inclusion of an “extra” validation object, which is merged into the main ORM validation object namespace.

    This is documented briefly here.

    If I have understood correctly, I think you are looking to do something like this:

    // another script, e.g., a controller
    
    // Create the model
    $admin = ORM::factory('Admin');
    
    // $data = the data as an array, before serialization ...
    
    $extra_validation = Validation::factory($data)
                        // add ->rule() calls here, but DO NOT chain ->check()
                        ;
    
    // Set $data in the model if it is going to be saved, e.g., $admin->data = $data;
    // Set other data... e.g., $admin->foo = 'bar';
    
    // Save the model
    try {
        $admin->save($extra_validation);
    }
    catch (ORM_Validation_Exception $e)
    {
        // Manipulate the exception result
    }
    

    While in this example you must still create another validation object, you are now able to catch all exceptions in a single block. I would recommend using var_dump() or similar on $e->errors() to check the namespace if you are using i18n messages to provide a human-readable error message. You should find that a namespace called “_external” has been created in the response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've noticed in Kohana 3 these error messages provided by default. return array( 'not_empty'
What wrong with this validation: Jquery: $(document).ready(function(){ $(#addcmd).attr(disabled,disabled); $(#cmdstxt).keypress( function(event){ var txt=$(#cmdstxt); if( txt.val().length
I'm using Kohana validation library and I want to set up my own user
i can't find complete list of kohana validation rules list, can someone point me
validation work i use ($this->Form->input) <?php echo $this->Form->input('Car', array('type'=>'textarea','label'=>false, 'cols'=>'23', 'rows'=>'4'));?> and if i
I am using Jquery Validation . Currently, I have a username, what i want
I'm using jQuery validation plugin to validate a form. when one thing is selected
Kohana's Validation library has a pre_filter() method which lets you apply any PHP function
This is what I've found in the Kohana3 validator rules: public static function digit($str,
Is there a way to use Kohana's (3+) validation class without using message files?

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.