I need help to understand how to properly build a cakephp 1.3 datasource.
FYI, I'm still a beginner regarding OOP.
I'll use Mailchimp as an example. Mailchimp provides a "Wrapper" (http://www.mailchimp.com/api/downloads/) for their API.
My first question is : Is it overkill to build a datasource since they provide a wrapper ?
On with the development of a datasource...
I tried to find an existing datasource in the bakery to help me understand the building process.
For the following Vimeo datasource (http://bakery.cakephp.org/articles/view/vimeo-datasource) there's this comment :
Thank you for your contribution. I will publish this even though there are some issues, that I hope you will take into consideration for the Advanced version and it's article.
Your datasource does not map to the Datasource class. Implementing an abstract class like that ( http://api.cakephp.org/class/data-source ), you should overwrite it's methods. This will make it more readable and extendable by other developers as well as one crucial advantage: giving it's model the ability to operate in a "normal" cake way using VimeoModel->find(). Please do this for your next iteration.
And in the cakephp book (http://book.cakephp.org/view/1076/Basic-API-For-DataSources) they mention that we should implement at least one of the following methods: create, read, update and/or delete.
Second question : Is the create, read, update and/or delete method are the only available methods ?
I tried creating an helloworld method in the datasource and call it like MailchimpModel->helloworld() in my controller but it doesn't find my method. My model is linked to the Mailchhimp datasource in the class properties.
The previous example works if I load the datasource with "ConnectionManager::getDataSource('mailchimp')" but it doesn't look like it's the proper way of doing this if I understand the comment that was left for the Vimeo datasource correctly.
Third question : How is the find method of the model related to the read method of the datasource ?
- If I return "Hello World" in the read method of the datasource I'm able to get it like this MailchimpModel->find('all');
Fourth question : How do I convert all the methods from the Mailchimp wrapper to the datasource class if the only method available is MailchimpModel->find()?
Thanks!