简体   繁体   中英

What is wrong with my php/cakephp syntax?

Although I'm doing this in cakephp, i believe I have a terrible php-syntax-newbie-mistake in my code, but I can't decipher the correct way.

The mistake is in the line:

'logo' => $validateArray

Apparently I have no clue on how to write that line, without repeating the above text.

var $validateArray = array(
    'rule1' => array(
        'rule' => 'isCompletedUpload',
        'message' => 'File was not uploaded '  
    ),
    'written' => array( 
        'rule' => 'isSuccessfulWrite', 
        'message' => 'blah'
     )
);
public $validate = array(
    'logo' => $validateArray
);

The initialization of class property must be a constant value , can't contain a variable.

You need to initialize it in the constructor instead.

public $validate;

public function __construct() {
  $this->validate = array(
    'logo' => $this->validateArray;
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM