2015-10-05 44 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');