简体   繁体   English

CodeIgniter / DataMapper:重用对象

[英]CodeIgniter/DataMapper: reuse object

I use this to count all active users in a database, works like it should: 我用它来计算数据库中的所有活动用户,其工作方式如下:

$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();

Now I also want to use the (same) object to count all inactive users, therefore I want to use this: 现在,我还想使用(相同)对象来计数所有不活动的用户,因此我想使用这个:

$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();
$data['users_inactive'] = $ouser->where(array('active'=>0))->count();

But this doesn't seem to work. 但这似乎不起作用。 Clearing the object first doesn't work either: 首先清除对象也不起作用:

$ouser = new User;
$data['users_active'] = $ouser->where(array('active'=>1))->count();
$ouser->clear();
$data['users_inactive'] = $ouser->where(array('active'=>0))->count();

How can I resuse the same object, in this case for counting? 在这种情况下,如何重用同一对象进行计数?

可以在这里找到答案(Codeigniter / Datamapper论坛): http ://ellislab.com/forums/viewthread/149388/P915/#1054666

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM