0

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
moberemk
  • 1,597
  • 1
  • 18
  • 39

1 Answers1

1

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.

floriank
  • 25,546
  • 9
  • 42
  • 66
  • This is exactly what I wanted; thanks! Sorry if this seems like a newbie question; I'm still learning every day about all the fantastic features this framework has buried deep. – moberemk Aug 11 '13 at 18:19
  • I don't think it is in this case and your question shows that you put some effort into your problem already and try to come up with a good solution for your problem. Good luck with your implementation. :) Just ask another questions if you have problems. – floriank Aug 11 '13 at 23:28
  • Once you implement the Instagram datasource, share the love, submit it to the repo ;) I would love to see that resource grow. – alairock Aug 12 '13 at 01:07