Php 是否可以将模型与当前时间条件关联?
是否可能获得与当前时间条件相关的两个模型Php 是否可以将模型与当前时间条件关联?,php,cakephp,associations,cakephp-2.0,Php,Cakephp,Associations,Cakephp 2.0,是否可能获得与当前时间条件相关的两个模型 <?php class SomeModel extends AppModel { public $hasOne = array( 'ForumBan', 'ForumBanActive' => array( 'className' => 'ForumBan', 'conditions' => array('ForumBanActive.en
<?php
class SomeModel extends AppModel {
public $hasOne = array(
'ForumBan',
'ForumBanActive' => array(
'className' => 'ForumBan',
'conditions' => array('ForumBanActive.end_time >' => time()) // fatal error
),
);
}
php OOP的基本课程:不能在对象属性声明中调用方法和函数 在模型的_construct()方法中设置关联,或使用bindModel() 就像我说的,谢谢@burzum的建议,但从我的答案中抄袭过去的解决方案并不酷,你真丢脸! 按照@burzum的回答,我得到了想要的结果
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);
谢谢你的帮助,但你为什么要转发我的答案?
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->hasOne['ForumBanActive']['conditions'] = array('ForumBanActive.end_time >' => time()));
}
public $hasOne = Array(
'ForumBan',
'ForumBanActive' => array('className' => 'ForumBan'),
'UserFile',
'BlogProfile',
);