Answer can be found here (Codeigniter/Datamapper forum): http://ellislab.com/forums/viewthread/149388/P915/#1054666
CodeIgniter/DataMapper: reuse object
-
31-05-2022 - |
Question
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?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow