2015-10-05 46 views
0

我是新来CakephpCakePHP的配置::阅读()错误

我需要在所有的模型和控制器使用的变量。

bootstrap.php

Configure::write('TimeField', 'time'); 

AppController.php

public $TimeField = Configure::read('TimeField'); 

以上行给出错误:

Error: syntax error, unexpected '(', expecting ',' or ';' File: D:\xampp\htdocs\inventory\app\Controller\AppController.php Line: 37

请指点。请让我知道是否应该遵循其他方法,因为我也需要在所有模型中使用此变量。

+2

[类物业PHP函数调用(可能的重复http://stackoverflow.com /问题/ 14665097/PHP的功能 - 通话中类属性) – ndm

回答

0

您不能在类属性声明中使用函数调用。

你应该申报

public $timeField; 

,然后用你的__construct初始化()方法

$timeField = Configure::read('TimeField');