CakePHP和Drupal 6需要互相交谈,但是怎么样?

时间:2021-04-18 14:03:55

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:

我有一个CakePHP应用程序需要从Drupal(6)获取数据。具体来说,有一个自定义内容类型和一个需要与CakePHP共享的webform - 所以当添加该内容类型的新节点或提交webform时,Cake知道它。我不确定最好的方法,我提出了两种方法:

  1. 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.
  2. 为相关模型提供备用数据源,并直接从Drupal数据库中读取。但是,Drupal表格是Drupally格式,我宁愿不写很多$ this-> Model-> find()s - 这会有点痛苦。我不完全了解Drupal在哪里存储所有内容。
  3. 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?
  4. 在Drupal中编写一些代码,以便在CakePHP数据库中以不同的格式保存数据。我不知道这会有多容易 - 我更喜欢Cake比Drupal更快。我想我会使用hook_form_alter并在$ form [#submit]数组中添加一个函数?

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

非常感谢,谢谢

2 个解决方案

#1


5  

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

我将在Drupal中创建一个Web服务API,并定期在Cake中运行一个批处理作业,该作业可以访问新数据的API。试试这个模块: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.

或者,如果您需要超级并发更新,请在Cake中创建API以接收数据,并在Drupal中创建一个模块,该模块将在提交时发送数据。

This way you don't need to worry about database-level sharing between the two.

这样您就不必担心两者之间的数据库级共享。

#2


0  

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.

假设Drupal和CakePHP应用程序存在于同一台服务器上,我想我会考虑在现有的Drupal数据库中创建Cake表。这样,您就不必担心数据源,API或更新,因为您可以看到表格。

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.

很多时候我不得不这样做,因为托管只有一个数据库实例。由于这个原因,Joomla和其他应用程序在表名前加上前缀。

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.

至于表的形状,您可以在模型定义中配置Cake以正确读取表(通过指定非常规id和fk名称等。

Always try to avoid having duplicate data that must be kept synchronised.

始终尽量避免重复必须保持同步的数据。

#1


5  

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

我将在Drupal中创建一个Web服务API,并定期在Cake中运行一个批处理作业,该作业可以访问新数据的API。试试这个模块: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.

或者,如果您需要超级并发更新,请在Cake中创建API以接收数据,并在Drupal中创建一个模块,该模块将在提交时发送数据。

This way you don't need to worry about database-level sharing between the two.

这样您就不必担心两者之间的数据库级共享。

#2


0  

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.

假设Drupal和CakePHP应用程序存在于同一台服务器上,我想我会考虑在现有的Drupal数据库中创建Cake表。这样,您就不必担心数据源,API或更新,因为您可以看到表格。

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.

很多时候我不得不这样做,因为托管只有一个数据库实例。由于这个原因,Joomla和其他应用程序在表名前加上前缀。

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.

至于表的形状,您可以在模型定义中配置Cake以正确读取表(通过指定非常规id和fk名称等。

Always try to avoid having duplicate data that must be kept synchronised.

始终尽量避免重复必须保持同步的数据。