cakephp - Cake PHP delimiter must not be alphanumeric or backslash with custom validation rule -
this question exact duplicate of:
- cake php custom validation rule 4 answers
i have issue i´d adress you. i´ve set custom validation rule within appmodel in class post.
'deliveryarea' => array( 'rule-1' => array( 'rule' => array('between', 5, 5), 'message' => 'bitte eine fünfstellige postleitzahl eingeben' ), 'rule-2' => array( 'rule' => 'numeric', 'message' => 'bitte nur zahlen eingeben' ), 'rule-3' => array( 'rule' => 'zipexists', 'message' => 'postleitzahl existiert nicht!' ) ) the function zipexists coded in appmodel in class zipcode.
public function zipexists($zipcode){ $valid = $this->find('count', array('conditions'=> array('zipcode.zipcode' =>$zipcode))); if ($valid >= 1){ return true; } else{ return false; } } debug($valid) throws correct numbers: 1 if function finds valid zipcode , 0 if not. said means function called properly. cake 2 things. first throws error: delimiter mustn´t alphanumeric or backslash. since trying array_push($zipcode); in function didn´t work don´t have clue on that.
second error message in view deliveryarea shown time, doesn´t matter if function threw true or false.
thanks in advance.
i found solution. cake wants custom validation rules in class rule called. so, when call custom rule in class post, custom function has written down in class post, otherwise cake won´t find , validate false everytime.
the magic here import appmodel-class want use in class call validation-function. works following statement:
$zipcode = classregistry::init('class use - in case "zipcode"');
but if tables associated each other hasany or belongsto , stuff, custom functions works without that. important point mustn´t miss is, validation functions has introduced "public function xyz" otherwise cake won´t find them too.
Comments
Post a Comment