I have a Cakephp 2 model with a class constant:
class Person extends AppModel
{
const NAME = 'MyName';
}
How can i access this class constant into the controller method ?
I try :
public function SayName( $id )
{
var_dump($this->Person->NAME);
die;
}
But the result was : NULL
You can also declare your model usage at the top of the controller with the command
App::uses('Person', 'Model');
Then you can access the model constant in the controller with
Person::NAME
It's a bit strange, but you'll want to do this:
$person = $this->Person;
var_dump($person::NAME);
PHP doesn't like the format $this->inst::CONSTANT
, so simply setting it as a variable (like above) will do the trick.