Exorcist
Exorcist

Reputation: 1

ORM/Extra Validate iby two field

Kohana 3.2

I want to check my parent_id but i need the second value of type_id. Code:

public function rules()
{ 
return array(
'type_id' => array(
array('not_empty'),
array('digit'),
),

'parent_id' => array(
array('digit'),
array(array($this,'check_category'),array(':value', ':field','type_id'))
),


);

}

public function check_category($parent_id,$field,$type_id)
{
die($type_id);
}

How to sent two values of my field to my function ??

After i make that in my controller :

if(isset($_POST['submit']))
        {
            $data = Arr::extract($_POST, array('type_id', 'parent_id', 'name', 'comment'));
            $category = ORM::factory('kindle_category');
            $category->values($data);

            try {
                $extra_rules = Validation::factory($_POST)
                ->rule('parent_id','Kindle::check_category',array($data['type_id'],$data['parent_id'],'parent_id',':validation'));
                $category->save($extra_rules);

                $this->request->redirect('kindle/category');
            }
            catch (ORM_Validation_Exception $e) {

                $errors = $e->errors('validation');

            }
        }

if($parent->type_id!=$type_id) 
            {
                $validation->error($field, 'Dog name, not cat!');
                return false;
            }

How to see my error "Dog name,not cat!' in my View ? Array errors doesnot have this value.

Upvotes: 0

Views: 364

Answers (1)

Thorsten
Thorsten

Reputation: 5644

public function rules()
{
    return array(
        'type_id' => array(
            array('not_empty'),
            array('digit'),
        ),

        'parent_id' => array(
            array('digit'),
            array(array($this,'check_category'),array(':validation'))
    ),
);

}

public function check_category($validation)
{
    $type_id = $validation['type_id'];
    ...
}

http://kohanaframework.org/3.2/guide/orm/examples/validation

Upvotes: 1

Related Questions