Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:26:55+00:00 2026-06-18T03:26:55+00:00

I’ve been following along with the Views 3 help files for Drupal 7, but

  • 0

I’ve been following along with the Views 3 help files for Drupal 7, 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:

<?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' => '',
    ),
  ),
);

//...

?>

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.

<?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;
}

Here’s my test.module file:

<?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);
}

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:26:56+00:00Added an answer on June 18, 2026 at 3:26 am

    I just set-up a basic module to test it and it works fine. The main problem I can see with your code is the settings.php file.

    settings.php

    <?php
    $databases = array (
      'default' => array (
          'default' => array (
          'database' => 'drupaldev',
          'username' => 'drupal_user',
          'password' => '',
          'host' => 'localhost',
          'port' => '',
          'driver' => 'mysql',
          'prefix' => '',
        ),
      ),
    
      'testdb' => array(
        'default' => array (
          'database' => 'testdb',
          'username' => 'testdb_user',
          'password' => '',
          'host' => 'localhost',
          'port' => '',
          'driver' => 'mysql',
          'prefix' => '',
        ),
      ),
    );
    

    so_views.module

    <?php
    
    /**
     * Implements hook_views_api().
     * 
     * @return array
     */
    function so_views_views_api() {
      return array(
        'api' => 3,
      );
    }
    
    /**
     * Implements hook_views_data().
     *
     * @return array
     */
    function so_views_views_data() {
      return array(
        'example_table' => array(
          'table' => array(
            'group' => t('SO View Table'),
            'base' => array(
              'field' => 'nid',
              'title' => t('SO new Table'),
              'help' => t('Table contains data'),
              'weight' => -10,
              'database' => 'testdb',
            ),
            'join' => array(
              'node' => array(
                'left_field' => 'nid',
                'field' => 'nid',
              ),
            ),
          ),
          'nid' => array(
            'title' => t('Node Id'),
            'help' => t('This is the node Id'),
            'relationship' => array(
              'base' => 'node',
              'base field' => 'nid',
              'handler' => 'views_handler_relationship',
              'label' => t('Default label for the relationship'),
              'title' => t('Title shown when adding the relationship'),
              'help' => t('More information on this relationship'),
            ),
          ),
          'plain_text_field' => array(
            'title' => t('Plain text field'),
            'help' => t('Just a plain text field.'),
            'field' => array(
              'handler' => 'views_handler_field',
              'click sortable' => TRUE, // This is use by the table display plugin.
            ),
            'sort' => array(
              'handler' => 'views_handler_sort',
            ),
            'filter' => array(
              'handler' => 'views_handler_filter_string',
            ),
            'argument' => array(
              'handler' => 'views_handler_argument_string',
            ),
          ),
          'numeric_field' => array(
            'title' => t('Numeric field'),
            'help' => t('Just a numeric field.'),
            'field' => array(
              'handler' => 'views_handler_field_numeric',
              'click sortable' => TRUE,
            ),
            'filter' => array(
              'handler' => 'views_handler_filter_numeric',
            ),
            'sort' => array(
              'handler' => 'views_handler_sort',
            ),
          ),
          'boolean_field' => array(
            'title' => t('Boolean field'),
            'help' => t('Just an on/off field.'),
            'field' => array(
              'handler' => 'views_handler_field_boolean',
              'click sortable' => TRUE,
            ),
            'filter' => array(
              'handler' => 'views_handler_filter_boolean_operator',
              // Note that you can override the field-wide label:
              'label' => t('Published'),
              // This setting is used by the boolean filter handler, as possible option.
              'type' => 'yes-no',
              // use boolean_field = 1 instead of boolean_field <> 0 in WHERE statment.
              'use equal' => TRUE,
            ),
            'sort' => array(
              'handler' => 'views_handler_sort',
            ),
          ),
          'timestamp_field' => array(
            'title' => t('Timestamp field'),
            'help' => t('Just a timestamp field.'),
            'field' => array(
              'handler' => 'views_handler_field_date',
              'click sortable' => TRUE,
            ),
            'sort' => array(
              'handler' => 'views_handler_sort_date',
            ),
            'filter' => array(
              'handler' => 'views_handler_filter_date',
            ),
          ),
        ),
      );
    }
    

    All the views related code came from the docs. I would recommend installing the advanced_help module and having a look at yoursite.com/views/api-tables.

    If you wanted to set this up in a different module then create an info file and the required sql can be found here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.