0

我想知道OctoberCMS后端的Backend\Behaviors\FormController类中更新的字段的模型名称这里是图片在这里 输入图片描述

这是在我自己的插件中更新表单后将触发的update_onSave()函数,该插件位于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;
    }
}

这是也位于Backend\Behaviors\FormController中的formAfterUpdate(),它将在保存更新表单后触发。

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

}

我想知道我的插件中的模型名称已经更新,但它只显示像这样更新的字段。

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

1 回答 1

1

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

如果您目前正在使用实现Backend\Behaviors\FormController甚至在内部的控制器,Backend\Behaviors\FormController您可以像这样获得模型类\名称

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

就像简单地form Behavior要求配置一样,update model您可以从config它自己获取该数据

看看这张图片

在此处输入图像描述

如果您有任何疑问,请发表评论。

于 2018-09-14T08:43:40.950 回答