Solved

Help with a Kohana ORM Validation problem

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Curl to output a url 7 46
Designing forms 3 17
WordPress 8 25
Dreamweaver code color same as CS6 or CS2015 2 8
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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 dynamically set the form action using jQuery.

809 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