Solved

Help with a Kohana ORM Validation problem

Posted on 2014-09-05
5
232 Views
Last Modified: 2014-09-10
Hi All,
I'm having a problem using Kohana's ORM validation.  I've checked all over the web but can't seem to find an answer that addresses it.   Whenever I create a User model and run create_validate and then check() it gives me a result in the webpage errors that "Could not Validate Array", which is a bit less than helpful.  Just to give some background on it my register() function is:

UserAccount.php <- Controller

$user = new Model_User;
$post = $this->request->post();

$userparams = array();
$userparams[ 'first_name'] = $post[ 'FirstName' ];
$userparams[ 'last_name'] = $post['LastName']';
$userparams['password'] = $post['Password'];
$userparams['passconf'] = $post['PassConf'];
$usercheck = $user->validate_create( $userparams );
if( $usercheck->check() )
{
.....
$user->values($userparams);
$user->save();
....
}

User.php <- Model

public function rules()
    {
        return array
        (            
            'password'              => array
            (
                array( 'not_empty', NULL ),
                array( 'min_length', array( ':value', 6 ) ),
                array( 'max_length', array( ':value', 128 ) )
            ),
            'passconf'              => array
            (
                array( 'matches', array( ':validation', 'passconf', 'password' ) )
            ),
            'first_name'             => array
            (
                array( 'not_empty' ),
                array( 'max_length', array( ':value', 45 ) ),
                array( 'regex', array( ':value', '/^[-\pL\pN_.]++$/uD') )
            ),
            'last_name'              => array
            (
                array( 'not_empty' ),
                array( 'max_length', array( ':value', 45 ) ),
                array( 'regex', array( ':value', '/^[-\pL\pN_.]++$/uD') )
            ) );
}

    public function validate_create( $array )
    {
            $ruleArr = $this->rules();
            
        $array = Validation::factory( $array )
                ->rules( 'first_name', $ruleArr[ 'first_name' ] )
                ->rules( 'last_name', $ruleArr[ 'last_name' ] )
                ->rules( 'password', $ruleArr[ 'password' ] )
                ->rules( 'passconf', $ruleArr[ 'passconf' ] );
        return $array;
}

Sorry about putting all the code here, I thought it would be easier to look at the multiple classes without having to go back and forth between files.  Any questions let me know and I'll be happy to get any information.
Thanks in advance.
0
Comment
Question by:William-B
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 40307255
I don't know Kohana, but I googled it to see if I could help. One thing I noticed is that v3.0 uses Validate:factory and v3.2 uses Validation::factory

Is it possible you're using the wrong one? Which version are you using?
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 40307268
It looks like you should be using the "rule" method of the validation class, rather than "rules".

ie
  $array = Validation::factory( $array )
                ->rule( 'first_name', $ruleArr[ 'first_name' ] )
                ->rule( 'last_name', $ruleArr[ 'last_name' ] )
                ->rule( 'password', $ruleArr[ 'password' ] )
                ->rule( 'passconf', $ruleArr[ 'passconf' ] );

Open in new window

0
 

Author Comment

by:William-B
ID: 40308724
Thanks for your response.  I was using example code from Kohana 2.x and didn't realize that they removed the 's' from rules.  Now my array is ok but I'm getting an error saying:  Undefined offset: 1, which I have absolutely no idea what it means.  If anyone knows why that would be happening that would be great.  I've checked through all my Debug::vars outputs and everything seems to be correct.  Let me know if you need any other information.  Thanks again.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 40309499
Do you get a line number and file with the error?
0
 

Author Comment

by:William-B
ID: 40314522
No it didn't give me that, but it happens inside the check() method.  I'm assuming that some of the data I'm passing is no good.  I'm going to track down the problem but since you solved my main problem, full points.  Thanks again.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question