CakePHP and Drupal 6 need to talk to each other, but how?
I have a CakePHP app which needs to take data from Drupal (6). Specifically, there is one custom content type and one webform that need to be shared with CakePHP - so when a new node for that content type is added, or a webform submitted, Cake knows about it. I'm not sure the best way to do this, I've come up with two approaches:
- Having an alternative datasource for the models in question, and read directly from the Drupal database. However, the Drupal tables are in a Drupally format, which I'd rather not write lots of $this->Model->find()s for - it will be a bit of a pain. I don't totally understand where Drupal stores everything, either.
- Writing some code in Drupal to save the data in a different format in the CakePHP database. I don't know how easy this would be - I'm more up to speed with Cake than Drupal. I guess I'd use hook_form_alter and add a function to the $form[#submit] array?
Does anyone have advice about which of these two would be better, or if there's another option? I'm leaning towards the second idea.开发者_开发知识库
Help greatly appreciated, thanks
I would create a web services API in Drupal, and periodically run a batch job in Cake which hits the API for new data. Try this module: http://drupal.org/project/services
Or, if you need super-concurrent updates, create an API in Cake to receive data, and a module in Drupal which will send data on submission.
This way you don't need to worry about database-level sharing between the two.
Assuming the Drupal and CakePHP applications exist on the same server, I think I would look at creating the Cake tables in the existing Drupal database. This way, you don't have to worry about datasources, APIs or updates as you can just see the tables.
A lot of times I've had to do this beacuse the hosting only came with one db instance. Joomla and other applications prefix the table names for this very reason.
As for the shape of the table, you can configure Cake, in the model definition, to read the table correctly (by specifiying non-conventional id and fk names etc.
Always try to avoid having duplicate data that must be kept synchronised.
精彩评论