Vtiger自定义模块无法保存

时间:2014-09-29 09:25:09

标签: php module vtiger

我正在vtiger中创建自定义模块,这是Vehicles.php中的Modules/Vehicles文件:

<?php

include_once 'modules/Vtiger/CRMEntity.php';

class Vehicles extends Vtiger_CRMEntity {
    var $table_name = 'vtiger_vehicles';
    var $table_index= 'vehiclesid';

    var $customFieldTable = Array('vtiger_vehiclescf', 'vehiclesid');

    var $tab_name = Array('vtiger_crmentity', 'vtiger_vehicles', 'vtiger_vehiclescf');

    var $tab_name_index = Array(
            'vtiger_crmentity' => 'crmid',
            'vtiger_vehicles' => 'vehiclesid',
            'vtiger_vehiclescf'=>'vehiclesid');

    var $list_fields = Array (
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Reg No' => Array('vehicles', 'reg_no'),
            'Assigned To' => Array('crmentity','smownerid')
    );
    var $list_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Reg No' => 'reg_no',
            'Assigned To' => 'assigned_user_id',
    );

    // Make the field link to detail view
    var $list_link_field = 'reg_no';

    // For Popup listview and UI type support
    var $search_fields = Array(
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Reg No' => Array('vehicles', 'reg_no'),
            'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
    );
    var $search_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Reg No' => 'reg_no',
            'Assigned To' => 'assigned_user_id',
    );

    // For Popup window record selection
    var $popup_fields = Array ('reg_no');

    // For Alphabetical search
    var $def_basicsearch_col = 'reg_no';

    // Column value to use on detail view record text display
    var $def_detailview_recname = 'reg_no';

    // Used when enabling/disabling the mandatory fields for the module.
    // Refers to vtiger_field.fieldname values.
    var $mandatory_fields = Array('reg_no','assigned_user_id');

    var $default_order_by = 'reg_no';
    var $default_sort_order='ASC';
    /**
 * Invoked when special actions are performed on the module.
* @param String Module name
* @param String Event Type
*/
function vtlib_handler($moduleName, $eventType) {
    global $adb;
    if($eventType == 'module.postinstall') {
        // TODO Handle actions after this module is installed.
    } else if($eventType == 'module.disabled') {
        // TODO Handle actions before this module is being uninstalled.
    } else if($eventType == 'module.preuninstall') {
        // TODO Handle actions when this module is about to be deleted.
    } else if($eventType == 'module.preupdate') {
        // TODO Handle actions before this module is updated.
    } else if($eventType == 'module.postupdate') {
        // TODO Handle actions after this module is updated.
    }
}
}

创建模块的文件是:

<?php
include_once('vtlib/Vtiger/Module.php');

/**
*Init instance
*/
$Vtiger_Utils_Log = true;

$MODULENAME = 'Vehicles';

$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
    $moduleInstance->delete();
} else {
    $moduleInstance = new Vtiger_Module();
    $moduleInstance->name = $MODULENAME;
    $moduleInstance->parent= 'Inventory';
    $moduleInstance->save();

    // Schema Setup
    $moduleInstance->initTables();

    //Bring on the blocks
    $block = new Vtiger_Block();
    $block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
    $table = "vtiger_".strtolower($moduleInstance->name);
    $moduleInstance->addBlock($block);

    $blockcf = new Vtiger_Block();
    $blockcf->label = 'LBL_CUSTOM_INFORMATION';
    $moduleInstance->addBlock($blockcf);

    $field1  = new Vtiger_Field();
    $field1->name = 'reg_no';
    $field1->label= 'Registration Number';
    $field1->uitype= 2;
    $field1->table = $table;
    $field1->column = $field1->name;
    $field1->columntype = 'VARCHAR(255)';
    $field1->typeofdata = 'V~M';
    $block->addField($field1);
    $moduleInstance->setEntityIdentifier($field1);

    $field2  = new Vtiger_Field();
    $field2->name = 'chas_no';
    $field2->label= 'Chassis Number';
    $field2->uitype= 2;
    $field2->column = $field1->name;
    $field2->columntype = 'VARCHAR(255)';
    $field2->typeofdata = 'V~O';
    $field2->table = $table;
    $block->addField($field2);

    $field3 = new Vtiger_Field();
    $field3->name= 'cust_name';
    $field3->label = 'Customer';
    $field3->uitype = 10;
    $field3->column = $field3->name;
    $field3->columntype ='VARCHAR(255)';
    $field3->typeofdata ='V~M';
    $field3->table = $table;
    $block->addField($field3);
    $field3->setRelatedModules(Array('Contacts'));

    // Recommended common fields every Entity module should have (linked to core table)
    $mfield1 = new Vtiger_Field();
    $mfield1->name = 'assigned_user_id';
    $mfield1->label = 'Assigned To';
    $mfield1->table = 'vtiger_crmentity';
    $mfield1->column = 'smownerid';
    $mfield1->uitype = 53;
    $mfield1->typeofdata = 'V~M';
    $block->addField($mfield1);

    $mfield2 = new Vtiger_Field();
    $mfield2->name = 'CreatedTime';
    $mfield2->label= 'Created Time';
    $mfield2->table = 'vtiger_crmentity';
    $mfield2->column = 'createdtime';
    $mfield2->uitype = 70;
    $mfield2->typeofdata = 'T~O';
    $mfield2->displaytype= 2;
    $block->addField($mfield2);

    $mfield3 = new Vtiger_Field();
    $mfield3->name = 'ModifiedTime';
    $mfield3->label= 'Modified Time';
    $mfield3->table = 'vtiger_crmentity';
    $mfield3->column = 'modifiedtime';
    $mfield3->uitype = 70;
    $mfield3->typeofdata = 'T~O';
    $mfield3->displaytype= 2;
    $block->addField($mfield3);

    // Filter Setup
    $filter1 = new Vtiger_Filter();
    $filter1->name = 'All';
    $filter1->isdefault = true;
    $moduleInstance->addFilter($filter1);
    $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);

    // Sharing Access Setup
    $moduleInstance->setDefaultSharing();

    // Webservice Setup
    $moduleInstance->initWebservice();
    }

一切运行良好:

创建模块车辆......已启动

初始化模块权限...完成

更新tabdata文件...完成

设置共享访问选项...完成

添加到菜单库存...完成

更新parent_tabdata文件...已启动

更新parent_tabdata文件...完成

创建模块车辆......完成

创建块LBL_VEHICLES_INFORMATION ...完成

LBL_VEHICLES_INFORMATION的模块语言条目...检查

创建块LBL_CUSTOM_INFORMATION ...完成

LBL_CUSTOM_INFORMATION的模块语言条目...检查

创建字段reg_no ... DONE

注册号的模块语言映射...检查

设置实体标识符... DONE

创建字段chas_no ... DONE

机箱编号的模块语言映射...检查

创建字段cust_name ... DONE

客户的模块语言映射...检查

将cust_name关系设置为Contacts ... DONE

创建字段assigned_user_id ...完成

分配给...的模块语言映射...检查

创建Field CreatedTime ... DONE

创建时间的模块语言映射...检查

创建字段ModifiedTime ... DONE

修改时间的模块语言映射...检查

创建全部筛选...完成

将过滤器全部设置为状态[0] ...完成

将reg_no添加到所有过滤器...完成

将chas_no添加到所有过滤器... DONE

将cust_name添加到所有过滤器... DONE

将assigned_user_id添加到所有过滤器...完成

重新计算共享规则...完成

初始化网络服务支持...完成

该模块运行良好,但无法添加记录,但在保存后显示: On Save

我错过了什么以及如何解决错误?

1 个答案:

答案 0 :(得分:0)

错误在$field2->column = $field1->name;行,

应为$field2->column = $field1->name;