4

I want to show some fields of a database table with Views. There is no node type, fields, or something like that for this database table. How can I do that?

1

1 Answer 1

4

If you are using Drupal 6 and Views 2, the easiest way to accomplish this is by utilizing the Data module.

If you can't use the Data module and have to do this programmatically for one reason or another, the following steps will get you on your way to achieving your goal of being able to manage your custom tables through the Views GUI. The first step is implementing hook_views_api() in a custom module. hook_views_api() tells which version of Views you are working with and will be similar to the code below:

function mymodule_views_api() {
  return array('api' => 2.0);
}

Change the version number depending on which version of Views you are using. Then you will define your table structures in hook_views_data(). It is a fairly lengthy discussion, so I will point you to the resource at http://views-help.doc.logrus.com/help/views/api-tables on how to do this.

In order to add fields, sorts, etc. using your table's fields, you will have to add "handlers" to the various field definitions in hook_views_data(). The documentation at http://views-help.doc.logrus.com/help/views/api-handlers is a great overview of how handlers work, and the article by Treehouse Agency is a good working example of creating handlers and adding them to your fields.

Views programming is very tough at first, and it is always helpful to look at the built in examples that come with Views. For example, the modules/node.views.inc file will have the hook_views_data() implementation for the core Node module, and the module/node directory will contain all of the handlers it utilizes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.