来自相关模块的Vtiger更新字段值

时间:2019-03-05 13:02:10

标签: php vtiger

我在模块发票的Save.php上有一个代码:

    public function saveRecord($request) {
        ...
        $received = $request->get('received');
        $balance = $request->get('balance');

        $relProject = $request->get('relProject');
        $project = Project_Record_Model::getInstanceById($relProject);

            $fields = $project->getField('cf_938');
            $fieldInstance = Vtiger_Field::getInstance($fields->id);


            if ($fieldInstance) {
                $fieldInstance->value = $received;
                $fieldInstance->save();
            }
   }

为什么save()不起作用?保存发票时,我的字段未在项目上更新。我需要对其进行修复。

1 个答案:

答案 0 :(得分:0)

您应该使用Record Model对象来编辑记录,而不是Field Model。尝试这样的事情:

public function saveRecord($request) {
        ...
        $received = $request->get('received');
        $balance = $request->get('balance');

        $relProject = $request->get('relProject');
        $project = Project_Record_Model::getInstanceById($relProject);

        $project->set('mode', 'edit');
        $project->set('cf_938', $received);
        $project->save();
   }