0

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
);
2
  • Hello aziz.punjani, I'm using 5.3.8 Commented Sep 24, 2012 at 2:38
  • 1
    you probably want the $validate array populated inside of the __construct to be $this->validate = array('logo' => $this->validateArray); Commented Sep 24, 2012 at 2:39

1 Answer 1

3

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;
  );
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, is great to know. If the array "$validateArray" never changes. Is there a way to declare it constant?
Because when I try to use the construct like this, cakePHP gives me thi error "Error: Table for model was not found in datasource default."
@FloresRobles Try read cakePHP's document and follow the example. I'm sorry I'm not familiar with cakePHP.
Thanks, finally i got it working. Using your way, just added parent::__construct($options); which was tricky for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.