如何定义系统配置?

发布于 2025-01-14 06:21:48 字数 2656 浏览 0 评论 0原文

我使用oro平台v4.1 我尝试根据系统定义配置值 https://doc.oroinc.com/4.1/backend/system-configuration/< /a>

so

class Configuration implements ConfigurationInterface
{

    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('web_sys_visit');

        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        SettingsBuilder::append($rootNode, [
            'nogps' => [
                'value' => true,
                'type' => 'boolean',
            ]
        ]);


        return $treeBuilder;
    }
}

和 system_configuration.yml

system_configuration:
    groups:
        websys_visit_settings:
            title: visit setting
    fields:
        web_sys_visit.nogps:
            data_type: boolean
            type: Oro\Bundle\ConfigBundle\Form\Type\ConfigCheckbox
            priority: 10
            options:
                label: No GPS
    tree:
        system_configuration:
            platform:
                children:
                    general_setup:
                        children:
                            application_settings:
                                children:
                                    websys_visit_settings:
                                        children:
                                            - web_sys_visit.nogps
class WebSysVisitExtension extends Extension
{
    const ALIAS = 'web_sys_visit';

    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('form.yml');
    }

    /**
     * {@inheritDoc}
     */
    public function getAlias()
    {
        return self::ALIAS;
    }
}

当我尝试清除缓存时出现以下错误

系统配置变量“web_sys_visit.nogps”未定义。请确保将其添加到捆绑配置中
设置或在 config.php 中标记为“ui_only”

所以我将

ui_only: true

添加到配置中并清除缓存,然后运行 ​​oro:entity-config:update

我在系统配置中看到 gps 配置 但 当我设置值 true 时,它​​没有保存

,我检查数据库中的 oro_confige_value 表,没有配置为 nog​​ps (部分= web_sys_visit) 我应该运行任何命令吗? 你能帮我吗? 谢谢

I use oro platform v4.1
I try to defind configuration value to system according to
https://doc.oroinc.com/4.1/backend/system-configuration/

so

class Configuration implements ConfigurationInterface
{

    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('web_sys_visit');

        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        SettingsBuilder::append($rootNode, [
            'nogps' => [
                'value' => true,
                'type' => 'boolean',
            ]
        ]);


        return $treeBuilder;
    }
}

and system_configuration.yml

system_configuration:
    groups:
        websys_visit_settings:
            title: visit setting
    fields:
        web_sys_visit.nogps:
            data_type: boolean
            type: Oro\Bundle\ConfigBundle\Form\Type\ConfigCheckbox
            priority: 10
            options:
                label: No GPS
    tree:
        system_configuration:
            platform:
                children:
                    general_setup:
                        children:
                            application_settings:
                                children:
                                    websys_visit_settings:
                                        children:
                                            - web_sys_visit.nogps
class WebSysVisitExtension extends Extension
{
    const ALIAS = 'web_sys_visit';

    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('form.yml');
    }

    /**
     * {@inheritDoc}
     */
    public function getAlias()
    {
        return self::ALIAS;
    }
}

when I try to clear the cache I have the below error

The system configuration variable "web_sys_visit.nogps" is not defined. Please make sure that it is either added to bundle configuration
settings or marked as "ui_only" in config.

so I add

ui_only: true

to the configuration and clear cache and then run oro:entity-config:update

I see gps configuration in system configuration
but
when I set value true, It was not saved

I check oro_confige_value table in db ,there is no config as nogps ( section =web_sys_visit)
should I run any command?
could you help me?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2025-01-21 06:21:48

ui_only 表示框架不会自动保存该值,您必须手动处理它。

看来配置类没有加载。确保命名空间和文件路径正确,并且您的包类名称为 WebSysVisitBundle,否则扩展名称不正确。

ui_only means that the value is not saved automatically by the framework and you have to handle it manually.

It seems the Configuration class is not loaded. Make sure namespaces and file paths are correct and your bundle class name is WebSysVisitBundle, otherwise the extension name is incorrect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文