moberemk
moberemk

Reputation: 1625

Extend CakePHP Find Method

For my latest project I need to pull extra data from another data API (specifically Instagram) and display it alongside the user's stored database information. I'd like to do it in a way that hooks in nicely with the existing Cake database calls, adding information to the returned User array.

While I know I could do that just by implementing a new method in the model, I'd ideally like to do it in a way that adds that information automatically to all calls to the User model, not just when I call a custom method; is this even possible?

Upvotes: 0

Views: 257

Answers (1)

floriank
floriank

Reputation: 25698

Yes it is and it's called a data source. The book comes with a complete example of how to talk to a foreign API using a data source.

When you implemented the data source for your API you can use it with any model (configure it to use the data source) and simply to read(), save() and find() calls.

There is also a repository with data sources for CakePHP, not including instragram but you might want to have example implementations to look at.

Upvotes: 1

Related Questions