0

i have gone through this line of code severally and i dont know why its throwing the error

in my AppModel.php i have this function:

public function getErrorMessage($key) {
    return $this->Message->get('validation.' . get_class($this) . '.' .     $key);
} 

Then in Employee Model validation code i have this:

public $validate = array(
    'payroll_no' => array(
        'numeric' => array(
            'rule' => array('naturalNumber'),
            'message' => $this->getErrorMessage('numeric')
        )
)

am getting error :

syntax error, unexpected '$this' (T_VARIABLE) 

on the line where am setting the message

am using php 5.5.3 on ubuntu and cakephp 2.5.4

GOA
  • 91
  • 1
  • 9
  • 2
    You can not use a method in a class variable `'message' => $this->getE...` – swidmann Dec 07 '15 at 11:34
  • @swidmann so how do you suggest i go about it.since the method returns string i thought i'd just assign the return value to message – GOA Dec 07 '15 at 11:38
  • you can create a getter method for this, within a method it's ok to add values to a variable like this – swidmann Dec 07 '15 at 11:41
  • 2
    @swidmann. i assigned it within the constructor and its ok now – GOA Dec 07 '15 at 11:52

0 Answers0