Reputation: 20545
One of my views have to display data that is from an external API call.
To manage all of these API calls i have create a component.
Now in order to costum paginate i have to create a function inside of my model however since i'm not using the models table but instead the component i have to call that component inside my model.
Is this possible or is there a work around?
Upvotes: 1
Views: 2361
Reputation: 25698
To manage all of these API calls i have create a component.
This is plain wrong, mostly because you don't have to. Technically you can but it would be wrong architecture wise.
The most correct way to implement API access in CakePHP would be to create a data source for that API and use that data source with a model.
The data source page in the CakePHP book comes with a complete example of how to create a data source that calls a foreign API.
Doing it as a data source allows you to use the API with multiple models which makes sense if the API provides different things. For example you could have a GithubUser and a GithubRepository model using a GithubDatasource. Also the data source is easier to test then a component.
Upvotes: 2
Reputation: 2860
I will suggest better to implement all functionality of component into model by creating functions within model.
And you can share that model for multipal controller.
and as your problem, over here you can use your model function within model.
Upvotes: 0