if there's an obvious answer to this question.
In my View function in my Controller I have a find() that counts the
number of times a user has voted on an object based on that object's
id which is being passed in to the View function:
function view($id = null) {
...
$timesVoted = $this->Object->Vote->find('count', array('conditions'
=> array('Vote.object_id' => $id, 'Vote.user_id' => $this->Auth-
>user('id'))));
$this->set('timesVoted', $timesVoted);
...
}
This works great. The count is returned. Now, how can I do the same
count in my Index function without that object id being passed in?
function index() {
// I can define my set of objects to loop through in the view:
$this->set('currentObjects', $this->Object->find('all',
array('order' => array('Object.modified DESC'), 'limit' => 20)));
// Now I need to once again count the number of times a user has
voted on each one of these 20 objects. Can I do that count here in the
Controller or in my $currentObjects foreach loop in my view? I can't
seem to find an obvious way to do it.
}
Any nudge in the right direction would be appreciated. I've been
reading about Elements and requestAction(), but those methods seem
like overkill for what seems to be a simple task.
Thanks,
Cale
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment