可以将模型与当前时间条件相关联吗?
Is possible to associate models with current time conditions?
是否可以得到与当前时间条件关联的两个模型?
<?php
class SomeModel extends AppModel {
public $hasOne = array(
'ForumBan',
'ForumBanActive' => array(
'className' => 'ForumBan',
'conditions' => array('ForumBanActive.end_time >' => time()) // fatal error
),
);
}
我不想每次在 ForumBan 模型上调用 find
时都添加此条件。
php OOP 中的基本课程:您不能在对象 属性 声明中调用方法和函数。 http://php.net/manual/en/language.oop5.properties.php
在模型的__construct()方法中设置关联或者使用bindModel():
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',
);
就像我说的,感谢@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',
);
是否可以得到与当前时间条件关联的两个模型?
<?php
class SomeModel extends AppModel {
public $hasOne = array(
'ForumBan',
'ForumBanActive' => array(
'className' => 'ForumBan',
'conditions' => array('ForumBanActive.end_time >' => time()) // fatal error
),
);
}
我不想每次在 ForumBan 模型上调用 find
时都添加此条件。
php OOP 中的基本课程:您不能在对象 属性 声明中调用方法和函数。 http://php.net/manual/en/language.oop5.properties.php
在模型的__construct()方法中设置关联或者使用bindModel():
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',
);
就像我说的,感谢@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',
);