使用OctoberCMS查找已在Backend \ Behaviors \ FormController中更新的字段的模型名称

问题描述 投票:0回答:1

我想知道在OctoberCMS后端的Backend \ Behaviors \ FormController类中已经更新的字段的模型名称这里是图片enter image description here

这是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}
octobercms octobercms-backend october-form-controller
1个回答
1
投票

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

如果你正在使用控制器实现Backend\Behaviors\FormController甚至在Backend\Behaviors\FormControlleryou内部可以获得Model 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"
}

简单地说form Behavior需要配置到update model所以你可以从config获取那些数据

看看这个图像

enter image description here

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

© www.soinside.com 2019 - 2024. All rights reserved.