Solved

Help with a Kohana ORM Validation problem

Posted on 2014-09-05
5
206 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
  • 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now