![](/img/trans.png)
[英]DataMapper For Codeigniter: Possible To Instantiate Model Object Just Once and Reuse?
[英]CodeIgniter/DataMapper: reuse object
我用它來計算數據庫中的所有活動用戶,其工作方式如下:
$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();
現在,我還想使用(相同)對象來計數所有不活動的用戶,因此我想使用這個:
$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();
$data['users_inactive'] = $ouser->where(array('active'=>0))->count();
但這似乎不起作用。 首先清除對象也不起作用:
$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();
$ouser->clear();
$data['users_inactive'] = $ouser->where(array('active'=>0))->count();
在這種情況下,如何重用同一對象進行計數?
可以在這里找到答案(Codeigniter / Datamapper論壇): http ://ellislab.com/forums/viewthread/149388/P915/#1054666
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.