tags:

views:

70

answers:

2

Let's say in my model, I have a function that queries two separate tables. I need to pass the results back to my controller to display in my view.

I'm using MongoDB but it should be the same for any other DB. Normally this would work.

$files = $grid->find(array("username" => $profile_id, 
                     "thumbnail" => array('$ne' => true)) );

$return files;

But, I need to go a step further and check to see if the user has a default photo selected.

$getCount = $grid->count(array("username" => $profile_id, 
                     "default" => array('$ne' => true)) );

If I recall correctly, I would normally do ...

$return array($files, $getCount);

Doesn't work though.

A: 

I'd split it into two separate model functions. I think its cleaner than fetching and returning the two separate pieces of data from the one function.

Stephen Curran
A: 

Figured it out ... in my function, I did the following.

$files['data'] = $grid->find(array("username" => $profile_id, 
                 "thumbnail" => array('$ne' => true)) );

$files['count'] = $grid->count(array("username" => $profile_id, 
                  "default" => array('$ne' => true)) );

$return files;

In my view, I would manipulate my data accordingly.

echo $files['count'];

foreach( $files['data'] as $obj) {
    ...
}
luckytaxi