Search Hook

Available Since: v1.1 (September 2009)


The hook_search method opens a module class to make it searchable to our SmartSearch module. By defining a public method called “hook_search” in your module’s primary class, you effectively tell the system how it should search your module. While this can be a complicated search involving numerous joins of supporting data - see the Projects module for an example - it can be quite simple also.

Each of the fields is relatively self-explanatory:


A simple example from the Links Module

public function hook_search()
    $search['table'] = 'links';
    $search['table_alias'] = 'l';
    $search['table_module'] = 'links';
    $search['table_key'] = 'link_id'; // primary key in searched table
    $search['table_link'] = 'index.php?m=links&a=addedit&link_id='; // first part of link
    $search['table_title'] = 'Links';
    $search['table_orderby'] = 'link_name';
    $search['search_fields'] = array('l.link_name', 'l.link_url', 'l.link_description');
    $search['display_fields'] = $search['search_fields'];

    return $search;

A more complex example from the Project Module:

public function hook_search() {
    $search['table'] = 'projects';
    $search['table_alias'] = 'p';
    $search['table_module'] = 'projects';
    $search['table_key'] = 'p.project_id'; // primary key in searched table
    $search['table_link'] = 'index.php?m=projects&a=view&project_id='; // first part of link
    $search['table_title'] = 'Projects';
    $search['table_orderby'] = 'project_name';
    $search['search_fields'] = array(
        'p.project_id', 'p.project_name',
        'p.project_short_name', 'p.project_location', 'p.project_description',
        'p.project_url', 'p.project_demo_url'
    $search['display_fields'] = $search['search_fields'];
    $search['table_joins'] = array(
            'table' => 'project_contacts',
            'alias' => 'pc',
            'join' => 'p.project_id = pc.project_id'

    return $search;

As you should be able to tell, this code does not perform the search. Instead, it simply tells the calling code how to search this module.

Assuming this method exists and includes the proper values, the SmartSearch module will automatically call this function. No further configuration is necessary.

Extending the System

Hooks are how we extend the system by allowing you to connect into specific processes and actions in standard, consistent ways with minimal effort without modifying Web2project core. This ensures you can accomplish what you need and your modules remain compatible through Web2project upgrades.

Available Since v3.0 (September 2013)

  • Workflow Hooks (pre-create, post-create, pre-delete, post-delete, pre-load, post-load, pre-store, post-store, pre-update, post-update)

Available Since v1.1 (September 2009)

  • Calendar Hook
  • Cron Hook
  • Search Hook