Solved

Help with a Kohana ORM Validation problem

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

636 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