I've been following along with the Views 3 help files, but I'm a bit stuck on what else I need to add to my module to make it visible to Views so I can use Views to display data in my external database.
Of course my real database has a lot more useful fields, but I was having trouble getting that to display--so I made this test database instead as a "hello world" before I try something more complex. Here's the schema.
database name = other
create table strings (
id int primary key auto_increment,
mystring varchar(50)
);
Here's my settings.php to include the database:
$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' => '',
),
),
);
and here's my test.views.inc file for my custom module named test (which is enabled) that describes to Drupal what the table structure of mystrings looks like.
//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;
}
Here's the current problem: When I try and make a new view I don't see any of this information or anything related to my database and table mystrings. Does anybody know what I'm doing wrong in my custom module code / view usage? Any help is much appreciated!
Comments
Did you clear the caches & other issues.
Did you clear the caches after enabling your module?
Also, can someone tell me why views insists on including a nid field in my query when I don't have any nid field defined in my data definition? (see http://groups.drupal.org/node/292993) for further discussion.