在drupal 7中为多站点共享来自不同数据库的表

时间:2012-10-19 06:56:39

标签: drupal-7

我正在建立一个drupal multisite,比如childone和childtwo。两者都有各自的数据库。现在要求是分享一些表格,例如。在站点childone中创建的用户必须在站点childtwo中具有相同的访问权限。 可以请任何人建议我使用正确的逐步解决方案吗?

问候

1 个答案:

答案 0 :(得分:3)

您需要使用表格前缀,而settings.php解释了如何完成此操作:

 * You can optionally set prefixes for some or all database table names
 * by using the 'prefix' setting. If a prefix is specified, the table
 * name will be prepended with its value. Be sure to use valid database
 * characters only, usually alphanumeric and underscore. If no prefixes
 * are desired, leave it as an empty string ''.
 *
 * To have all database names prefixed, set 'prefix' as a string:
 * @code
 *   'prefix' => 'main_',
 * @endcode
 * To provide prefixes for specific tables, set 'prefix' as an array.
 * The array's keys are the table names and the values are the prefixes.
 * The 'default' element is mandatory and holds the prefix for any tables
 * not specified elsewhere in the array. Example:
 * @code
 *   'prefix' => array(
 *     'default'   => 'main_',
 *     'users'     => 'shared_',
 *     'sessions'  => 'shared_',
 *     'role'      => 'shared_',
 *     'authmap'   => 'shared_',
 *   ),
 * @endcode

因此,对于您的示例,对于您的childone网站的settings.php,您将拥有以下内容:

'prefix' => array(
  'default'    => 'childone_',
  'user'       => 'shared_',
  'sessions'   => 'shared_',
  'role'       => 'shared_',
  'permission' => 'shared_',
);

对于childtwo的settings.php,它非常相似:

'prefix' => array(
  'default'    => 'childtwo_',
  'user'       => 'shared_',
  'sessions'   => 'shared_',
  'role'       => 'shared_',
  'permission' => 'shared_',
);

除了共享的表之外,所有表都将以childone_或childtwo_作为前缀,运行安装后将以shared_(或任何你想要的)作为前缀。