我一直在关注 Drupal 7 的 Views 3 帮助文件,但我有点坚持需要添加到我的模块以使其对 Views 可见,以便我可以使用 Views 在我的外部显示数据数据库。
当然,我的真实数据库有更多有用的字段,但我在显示时遇到了麻烦——所以在我尝试更复杂的东西之前,我将这个测试数据库改为“hello world”。这是架构。
database name = other
create table strings (
id int primary key auto_increment,
mystring varchar(50)
);
这是我的 settings.php 以包含数据库:
<?php
// ...
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupal',
'username' => 'drupal_user',
'password' => 'my_other_pass',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
array (
'database' => 'other',
'username' => 'my_user',
'password' => 'my_pass',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
//...
?>
这是我的名为 test (已启用)的自定义模块的 test.views.inc 文件,它向 Drupal 描述了 mystrings 的表结构是什么样的。
<?php
//useful site explaining all of this: http://groups.drupal.org/node/17236
function test_views_data() {
$data = array(
'strings' => array(
'table' => array(
'group' => t('views test'),
'base' => array(
'field' => 'id',
'title' => t("I guess node"),
'help' => t("help for I guess node I guess"),
'weight' => -10,
'database' => 'others',
),
),
'id' => array(
'title' => t('id'),
/*'field' => array(
'handler' => 'views_handler_field_node',
'click sortable' => TRUE,
),*/
'relationship' => array(
'label' => t("node I think"),
'base' => 'node',
'base_field => 'id',
),
/*'argument' => array(
'handler' => 'view_handler_argument_node_nid',
'name field' => 'id for strings',
'numeric' => TRUE,
'validate type' => 'nid',
),*/
/*'filter' => array(
'handler' => 'views_handler_filter_numeric',
),*/
/*'sort' => array(
'handler' => 'views_handler_sort',
),*/
),
'mystring' => array(
'title' => t('mystring'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
),
),
);
return $data;
}
这是我的 test.module 文件:
<?php
function test_help($section) {
switch($section) {
case "admin/help#test":
return "<p>hello from test</p>";
case "admin/modules#description":
return "hello from test inside the admin help thing";
}
}
function test_page() {
return "<p>hello from the actual test page</p>";
}
function test_views_api() {
return array('api' => 3.0);
}
这是当前的问题:当我尝试创建新视图时,我看不到任何此类信息或与我的数据库和表 mystrings 相关的任何内容。有人知道我在自定义模块代码/视图使用中做错了什么吗?任何帮助深表感谢!