views:

22

answers:

2

Hi i have made a custom validation in the model. How can i access the result($visitor) from this in the controller?

model:

<?php  
class Visitors extends AppModel 
{ 
    var $name = 'Visitors'; 

    var $validate = array(
        'xxx' => array(
            'rule' => array('checkxxx'),
            'message' => 'yyy.'
        )
    );

    function checkIxxx($check){
        $visitor = $this->find('first', array('conditions' => $check));
        return $visitor;
    }

} 

?>

in my controller i want this:

function start() {  
        $this->Visitors->set($this->data);      
        if($this->Visitors->validates()) 
        {  
          if($this->Visitors->xxx->type == 'value') //this is a value from the $visitor array in the model**
          {
               //do something
          }

        }

is this possible?

+1  A: 

Updated to be a relevant answer, apologies.

//Model
var myField = 'invalid';

function myValidation($var){
  if($var === true){
    // Passed your validation test
    $this->myField = 'valid';
  }else{
    $this->myField = 'invalid';
  }
}

// Controller
$this->Model->set($this->data);
$this->Model->validates($this->data);

if($this->Model->myfield == 'valid'){
  // Field has passed validation
}

You will want to use

$this->Model->invalidFields()
DavidYell
i am looking for the data that comes through when it validates successfully
Mikelangelo
Well there isn't any that I know of. Have you tried setting a variable in your models validate function and then looking for it in your controller?
DavidYell
A: 

PS: You dont follow cake conventions

the model should be "Visitor" (singular)

mark