CakePHP 和 Drupal 6 需要相互通信,但是如何通信呢?

发布于 2024-10-19 11:07:24 字数 503 浏览 2 评论 0原文

我有一个 CakePHP 应用程序,需要从 Drupal (6) 获取数据。具体来说,有一种自定义内容类型和一种 Web 表单需要与 CakePHP 共享 - 因此,当添加该内容类型的新节点或提交 Web 表单时,Cake 会知道这一点。我不确定执行此操作的最佳方法,我想出了两种方法:

  1. 为相关模型提供替代数据源,并直接从 Drupal 数据库读取。然而,Drupal 表采用 Drupally 格式,我不想为其编写大量 $this->Model->find() - 这会有点痛苦。我也不完全理解 Drupal 将所有内容存储在哪里。
  2. 在 Drupal 中编写一些代码,以将数据以不同的格式保存在 CakePHP 数据库中。我不知道这有多容易——我对 Cake 的了解比对 Drupal 的了解要快。我想我会使用 hook_form_alter 并向 $form[#submit] 数组添加一个函数?

有人建议这两者哪个更好,或者是否还有其他选择?我倾向于第二个想法。

非常感谢帮助,谢谢

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:

  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. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-10-26 11:07:24

我会在 Drupal 中创建一个 Web 服务 API,并定期在 Cake 中运行批处理作业,该作业会访问 API 以获取新数据。尝试这个模块: http://drupal.org/project/services

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

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

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.

悍妇囚夫 2024-10-26 11:07:24

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

很多时候我不得不这样做,因为托管只附带一个数据库实例。正是出于这个原因,Joomla 和其他应用程序为表名称添加前缀。

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文