2016-07-23 11 views
-2

パスワードをcpasswordと一致させたいのですが、私のmodel.phpファイルにエラーがあります。どうすればこのエラーを取り除くことができますか。そして事前にthanku: 構文エラー、予期しない '関数'(T_FUNCTION)、期待 ')'予期しない 'function'(T_FUNCTION)、予期している ')'

model file: 
App::uses('AppModel', 'Model'); 
class User extends AppModel { 

var $name = 'User'; 
var $useTable = 'users'; 
var $actsAs = array('Multivalidatable'): 
var $validationSets = array(
'AddUser' => array(

    public $validate = array(
     'cpassword' => array(
      'equaltofield' => array(
      'rule' => array('equaltofield','password'), 
      'message' => 'Require the same value to password.',    
      'on' => 'create', 
      ) 
      ), 
     ); 

    function equaltofield($check,$otherfield) 
    { 
     //get name of field 
     $fname = 'password'; 
     foreach ($check as $key => $value){ 
      $fname = $key; 
      break; 
     } 
     return $this->data[$this->name][$otherfield] === $this->data[$this->name][$fname]; 
    } 
'password'=>array(
        'notEmpty'=>array(
         'rule' => 'notBlank', 
         'message' => 'Please enter password ' 
        )      
       ), 
+3

StackOverflowは「私の無効なコードを修正する」サービスプロバイダではありません。このコードは間違っているとは言いませんが、PHPの基本情報(犯罪がない)についてもっと知る必要があるので、sytaxエラーが多すぎます。また、無効なスニペットはあなたが言及しているエラーを発生させることはありませんが、それは再現性がないため、あなたの質問をオフショピックにします。 – ndm

+1

[PHP Parse/Syntax Errors]の重複可能性があります。どのようにそれらを解決する?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) –

答えて

0

はこれを試してみてください:

 function equaltofield($check,$otherfield) 
    { 
      //get name of field 
     $fname = 'password'; 
     foreach ($check as $key => $value){ 
      $fname = $key; 
      break; 
     } 
     if($this->data[$this->name][$otherfield] === $this->data[$this->name][$fname]) { 
     return true; 
     } 
     return false; 
    } 

OR

使用equalTo検証ルール:

 var $validationSets = array('AddUser' => array(

     public $validate = array(
      'cpassword' => array(
       'rule' => array('equalTo', 'password'), 
       'message' => 'This password must be the equal', 
      ) 
    ); 

http://book.cakephp.org/2.0/en/models/data-validation.html#custom-validation-rules

関連する問題