Thursday, May 28, 2009

Associated models foreach loop/pagination - not sure how to include them.

I'm working with the searchable behaviour and have got it setup and
running OK, but I'm really not sure how I set associated data for
output in the view.

I have a search.ctp file which shows related data such as categories,
users etc. I know normally to retrieve the data I would just do a
find, but there is one variable set ($results), and I do not know how
to add in more data to be retrieved.

I have searched and tried various things include multiple for loops
(worked but the data wasn't linked to the search). There must be some
way of doing it, but I am still new to the cake way of doing things
and just can't seem to know how to do it.

This is the basic code:

function search($keyword = null) {
// Load SearchIndex Model:
$this->loadModel('SearchIndex');
$search = $this->SearchIndex->findAllById('search_index.id');
// Do search stuff:
$this->SearchIndex->searchModels(array('Post','Comment'));
$this->paginate = array(
'limit' => 10
);
$this->set('results', $this->paginate('SearchIndex'));
}

I need to fit in the associated models in there somewhere.... Any help
would be greatly appreciated!
--~--~---------~--~----~------------~-------~--~----~
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: