You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SuiteCRM v7.9中创建带关联筛选的自定义ListView页面

Got it, let's walk through how to build this custom filtered list page for your SuiteCRM 7.9 instance (based on Sugar 6.5 CE). This approach will mirror the standard ListView's look and feel (including checkboxes) but only show records linked to your other custom module. Here's a step-by-step breakdown:

1. Create a Custom Controller

First, we need a controller to handle the request for your custom list page. Create a new file at custom/modules/[YourCustomModule]/controllers/customlinkedlist.php:

<?php
require_once('include/MVC/Controller/SugarController.php');

class [YourCustomModule]ControllerCustomlinkedlist extends SugarController {
    public function action_list() {
        // Set the custom view we'll create next
        $this->view = 'customlinkedlist';
        
        // Check ACL permissions to ensure the user can access this module
        if(!$this->bean->ACLAccess('list')) {
            sugar_die($GLOBALS['app_strings']['LBL_NO_ACCESS']);
        }
    }
}

Replace [YourCustomModule] with the actual name of your module (e.g., MyCustomModule).

2. Build the Custom List View

Next, create a custom view that extends the standard ListView, so we can reuse most of its functionality but add our custom filter. Create custom/modules/[YourCustomModule]/views/view.customlinkedlist.php:

<?php
require_once('include/MVC/View/views/view.list.php');

class [YourCustomModule]ViewCustomlinkedlist extends ViewList {
    public function preDisplay() {
        parent::preDisplay();
        
        // Set a distinct page title to differentiate from the regular list
        $this->lv->listTitle = 'Linked ' . $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
    }

    protected function get_list_query($params = array()) {
        // Grab the base query from the parent ListView
        $query = parent::get_list_query($params);
        
        // Add custom join/filter to only include records linked to your other custom module
        // Replace [RelatedModule] with your associated module's name
        // Replace [link_name] with the relationship name between your two modules (find this in Studio > Relationships)
        $link = $this->bean->get_link_relationship('[link_name]');
        $related_table = $link->getJoinTable();
        $related_module_id_col = $link->getRelatedModuleIdColumn();
        
        // Use INNER JOIN to only keep records with existing association rows
        $query .= " INNER JOIN $related_table ON $related_table.id = {$this->bean->table_name}.id";
        $query .= " WHERE $related_table.$related_module_id_col IS NOT NULL";
        
        return $query;
    }
}

This overrides the default list query to filter out any records that don't have an active link to your target custom module.

3. Reuse Standard ListView Template (For Checkbox & UI Consistency)

To keep the checkbox functionality and UI matching the regular ListView, we don't need to build a new template from scratch. Since our view extends ViewList, it will automatically use your module's existing listviewdefs.php and list.tpl files.

If you want small UI tweaks (like a note explaining the filtered list), copy the default tpl to custom/modules/[YourCustomModule]/tpls/view.customlinkedlist.tpl and modify it:

<div class="alert alert-info">
    * This list only shows records linked to [RelatedModule]
</div>
{include file="modules/[YourCustomModule]/tpls/list.tpl"}
4. Add a Menu Item (Optional but User-Friendly)

To make this custom page easy to find, add a menu item to your module's navigation. Create or edit custom/modules/[YourCustomModule]/metadata/menudefs.php:

<?php
$module_menu[] = Array(
    "index.php?module=[YourCustomModule]&action=customlinkedlist",
    "Linked Records List",
    "Linked[YourCustomModule]",
    "[YourCustomModule]"
);

This adds a new option under your module's menu labeled "Linked Records List".

5. Clear Cache & Test

After setting up all files, head to Admin > Repair > Quick Repair and Rebuild to clear SuiteCRM's cache. Then access your custom page via the new menu item or direct URL: index.php?module=[YourCustomModule]&action=customlinkedlist.

You should see:

  • A filtered list of records only linked to your target custom module
  • Checkboxes next to each record (identical to the standard ListView)
  • Working bulk actions (if enabled for your module)
Quick Tips
  • Double-check relationship names and table columns via Studio or custom/modules/[YourCustomModule]/metadata/relationships.php if the filter doesn't work as expected.
  • Test with a non-admin user to confirm ACL permissions are enforced correctly.
  • If you need to adjust the query further (e.g., add additional filters), modify the get_list_query method in the custom view.

内容的提问来源于stack exchange,提问作者Jeffiekins

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:29:38