使用 OctoberCMS 查找已在 Backend\Behaviors\FormController 中更新的 field/s 的型号名称

Find the Model name of the field/s that has been updated in Backend\Behaviors\FormController using OctoberCMS

我想知道在 OctoberCMS 后端 Backend\Behaviors\FormController class 中更新的 field/s 的型号名称是图片 enter image description here

This is the update_onSave() function that will trigger after the form is updated in my own plugin this is located in Backend\Behaviors\FormController

/**
 * AJAX handler "onSave" called from the update action and
 * primarily used for updating existing records.
 *
 * This handler will invoke the unique controller overrides
 * `formBeforeUpdate` and `formAfterUpdate`.
 *
 * @param int $recordId Record identifier
 * @param string $context Form context
 * @return mixed
 */
public function update_onSave($recordId = null, $context = null)
{
    $this->context = strlen($context) ? $context : $this->getConfig('update[context]', self::CONTEXT_UPDATE);
    $model = $this->controller->formFindModelObject($recordId);
    $this->initForm($model);

    $this->controller->formBeforeSave($model);
    $this->controller->formBeforeUpdate($model);

    $modelsToSave = $this->prepareModelsToSave($model, $this->formWidget->getSaveData());
    Db::transaction(function () use ($modelsToSave) {
        foreach ($modelsToSave as $modelToSave) {
            $modelToSave->save(null, $this->formWidget->getSessionKey());
        }
    });

    $this->controller->formAfterSave($model);
    $this->controller->formAfterUpdate($model);

    Flash::success($this->getLang("{$this->context}[flashSave]", 'backend::lang.form.update_success'));

    if ($redirect = $this->makeRedirect('update', $model)) {
        return $redirect;
    }
}

This is the formAfterUpdate() located also in Backend\Behaviors\FormController that will trigger after the updating form is saved.

 /**
 * Called after the updating form is saved.
 * @param Model
 * 
 */
public function formAfterUpdate($model)
{
    echo $model;

}

I want to know the Model name from my plugin that has been updated but it only displays the fields that has been updated like this.

{"flagstateid":80,"name":"VIETNAM","code":"[VN]","image":null}

我想它比我们想象的要简单

如果您目前正在开发实现 Backend\Behaviors\FormController 的控制器,甚至在 Backend\Behaviors\FormController 内部,您可以像这样获得模型 Class\name

/**
 * Called after the updating form is saved.
 * @param Model
 */
public function formAfterUpdate($model)
{
    $modelName = $this->config->modelClass;
    // $modelName will be : "\HardikSatasiya\TimeTracker\Models\TimeLog"
}

As simply form Behavior require config to update model so you can get that data from config it-self

查看这张图片

如有疑问请评论。