views:

139

answers:

1

Hi,

I have a project that requires me to integrate with 2 REST APIs and then aggregate the results. I am building this project in CakePHP

My basic approach is:

Product (model) Products (controller) API1 (datasource) API2 (datasource) Aggregation (behaviour)

The basic flow is: 1. User enters a product name into a search form /products/search i.e 'DVD' 2. search() action on controller calls model->find() passing search term 3. search term is then passed to each datasource and the APIs return results 4. behaviour cleans, aggregates and reorders the results into a single dataset 5. model passes data back to controller, that then passes data onto the view 6. paginated results displayed on the search results page

This is where I get stuck...

Can a single model use 2 datasources and then use a behaviour to perform aggregation tasks.

I have only ever created a model that uses a single custom datasource.

Any ideas about the best way to do this would be really appreciated. The project scope is that the number of APIs integrated could grow to 10+ depending upon the success of this prototype project.

Thanks, Paul

+1  A: 

You can do something like this in your model

App::import('ConnectionManager');

$abc = ConnectionManager::getDataSource('abc');
$xyz = ConnectionManager::getDataSource('xyz');

$data1 = $abc->find('all');
$data1 = $xyz->find('all');
dogmatic69