Solved

Help with a Kohana ORM Validation problem

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 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

18 Experts available now in Live!

Get 1:1 Help Now