我需要在虚拟字段中使用配置值,类似于:
public $virtualFields = array(
'allow_modification' => ' CASE WHEN publish_date IS NULL OR publish_date + interval \''.Configure::read('Setting.app.allow_modification').'\' > NOW() THEN TRUE ELSE FALSE END'
);
但它不起作用。我知道它与PHP有关,但是在CakePHP中如何解决和修改virtualFields
呢?
答案 0 :(得分:1)
在virtualFields
构造函数中设置Model
(请参阅here):
class MyModel extends AppModel {
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->virtualFields['allow_modification'] = 'CASE WHEN publish_date IS NULL OR publish_date + interval \''.Configure::read('Setting.app.allow_modification').'\' > NOW() THEN TRUE ELSE FALSE END' ;
}
}