Вывод данных во views из сторонней базы данных

Перевод будет позже, взято из комментариев на drupal.org.

  1. Installed Data module with the patch in http://drupal.org/node/1074156 (comment #1).
  2. Created a stub structure of the tables I needed inside the Drupal database using Data.
  3. Used phpmyadmin to dump the SQL code for creating the tables in a separate DB.
  4. Copied the hook_views_data() export provided by the patched Data module into mymodule_views_data() hook (in mymodule.views.inc; it requires to define hook_views_api in mymodule.module). Notice the export code is provided per-table, you must copy it one by one and perform a few tweaks to the code.
  5. Decided which table to use as base and only left that one with the 'base' entry for the 'table' part of the views integration definition in hook_views_data().
  6. Added db_url['mydb'] entry to settings.php (remember to add 'default' key for the Drupal DB).
  7. Added the key 'database' to the views definition for the base table, with value 'mydb' (see 6).
  8. Remember to delete the stub tables definition from Data module.

And that's it, I didn't have to pollute the main Drupal DB and views got to offer me all its power :)

I highly recommend checking out the views documentation (install advanced_help) along with the steps I described to get the entire picture; I decided not to write a too detailed explanation to keep the general idea clear and simple.

I absolutely recommend Table Wizard for this. It doesn't only visualize your SQL table in Views, but it also tracks any changes you may do to that table (for example, when you add a column).


Немного рекламы:
- Интернет магазин на базе drupal + ubercart

Аватар пользователя garryson
Не в сети
Регистрация: 12 Сен 2013

Нашел здесь немало увлекательных и полезных статей. Эта одна из самых интересных.

Аватар пользователя xukaimin