Reputation: 1660
While CakePHP is a MVC framework, how can it take advantage when working with external REST API rather than its own Model?
Is there any way that I can interact with the API response, like how I'd interact with a cake Model?
This is what I'm currently doing:
$response = curlRequest('method',$param);
$this->set(compact('response'));
At this point I figured I don't even know how to use $Paginator->paginate()
from here on.
I just started CakePHP for some times, and I find that if I work with external API, the whole CakePHP thing become broken here and there. I'd suspect when working with API I shouldn't even use cake.
Upvotes: 1
Views: 1367
Reputation: 25698
if I work with external API, the whole CakePHP thing become broken here and there. I'd suspect when working with API I shouldn't even use cake.
That's complete nonsense. Most, if not all, frameworks provide some way to work with any kind of data source.
See http://book.cakephp.org/2.0/en/models/datasources.html
Taken from the above page:
Most people, however, are interested in writing datasources for external sources of data, such as remote REST APIs or even an LDAP server. So that’s what we’re going to look at now.
There is even a plugin for RESTful APIs:
https://github.com/neilcrookes/CakePHP-ReST-DataSource-Plugin
At this point I figured I don't even know how to use $Paginator->paginate() from here on.
This is doable, assuming you understand how pagination works at all you'll just have to get somehow the offset and total amount of records from the remote API to calculate the pagination. The Paginator in cake works together with a model and does a count query and a find('all') with limit and offset. Implement your API datasource and make a model using it.
Upvotes: 2