Flores Robles
Flores Robles

Reputation: 656

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
);

Upvotes: 0

Views: 90

Answers (1)

xdazz
xdazz

Reputation: 160883

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;
  );
}

Upvotes: 3

Related Questions