[英]OctoberCMS add custom fields in backend
如何在fields.yaml中添加字段,但阻止將它們添加到任何形式。 我只想使用“ formRenderField”方法添加這些字段
我想如果您想擴展它們,則可以直接在“ fields.yaml”文件中編寫並創建不同版本,並根據條件使用它們來呈現表單
<?php namespace Acme\Blog\Controllers;
class Categories extends \Backend\Classes\Controller
{
public $implement = ['Backend.Behaviors.FormController'];
public $formConfig = 'form_config.yaml';
}
這是正常的方法
但是您可以將條件放入構造函數中以更改配置文件
public __construct() {
// if condition is true then use this config otherwise use regular one
if(condition) {
$this->formConfig = 'modified_form_config.yaml';
}
}
另一種方法是根據條件擴展形式,例如:
UsersController::extendFormFields(function($form, $model, $context){
if (!$model instanceof UserModel)
return;
$form->addFields([
'store' => [
'label'=> 'Store',
'type'=>'relation',
'nameFrom'=> 'name'
],
]);
});
您可以在插件Boot方法中編寫此代碼
在這里,我們僅在調用UserController並嘗試呈現UserModel模型時添加字段。
如果您需要一些自定義方案,請描述更多,以便我們更好地為您提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.