Prestashop 预启动模块=>;如何从config.xml文件中获取值

Prestashop 预启动模块=>;如何从config.xml文件中获取值,prestashop,prestashop-1.7,Prestashop,Prestashop 1.7,我从Prestashop 1.7开始 我的问题是:如果无法通过Configuration::get(“[config.xml文件中的某些内容”)完成,如何访问和使用代码中的config.xml中的数据?为什么自定义模块的\u construct()中未填写的属性(如:$this->name,$this->tab,$this->description,$this->confirmUninstall)不会自动替换为config.xml文件中的等效值 以下是我尝试过的: 我一直在看 我一直在经历: 什

我从Prestashop 1.7开始

我的问题是:如果无法通过
Configuration::get(“[config.xml文件中的某些内容”)
完成,如何访问和使用代码中的
config.xml
中的数据?为什么自定义模块的
\u construct()
中未填写的属性(如:
$this->name
$this->tab
$this->description
$this->confirmUninstall
)不会自动替换为
config.xml
文件中的等效值

以下是我尝试过的:

我一直在看

我一直在经历:

  • 什么是预启动模块
  • 创建第一个模块
  • 关于config.xml文件
  • 添加配置页
  • 我体验了如何通过使用函数
    getContent()
    displayForm()
    来设置配置

    但是我不明白如何从
    config.xml
    文件中获取数据

    我的
    config.xml
    文件是这样的(在目录
    [PrestashopProject]\module
    中):

    我不明白为什么我的
    displayForm()
    函数末尾的
    Configuration::get('confirmUninstall')
    没有显示
    是否确实要卸载?
    它位于我的
    config.xml
    文件中

    同样在
    类mymodule extends Module
    \uuu construct()
    函数中,如果我不添加
    $this->author=“[author name]”我可以预期
    $this->displayName=$this->l('mymodule')
    它应该从
    config.xml
    文件匹配标记中提取数据,但它不这样做

    下面是我从@drot得到的第一个答案:

    我想知道我在这里遗漏了什么。它的最下面写着:

    在模块安装过程中,PrestaShop会自动在模块文件夹中创建一个小config.xml文件,该文件存储配置信息。手工编辑时,你应该非常小心

    的确,一开始,我手动创建了
    config.xml
    文件,因为我没有看到它最初弹出

    现在我从@drot得到了答案,我删除了我的
    config.xml
    文件,从Prestashop管理仪表板卸载了mymodule并重新安装了它

    我认为重新安装它会按照
    mymodule.php
    的要求创建
    config.xml
    文件。但事实并非如此,我是否错过了一个场景

    更新


    它最终创建了
    config.xml
    文件。我不知道是哪个动作触发了它,但它确实触发了。自动创建的
    config.xml
    文件内容与
    mymodule.php

    config.xml匹配,对您来说是无用的,因为它是自动生成的,正如用于优化后端模块列表加载的文档中所述

    这就是为什么您需要在模块构造函数中定义这些选项

    public function __construct() {
        ...
        $this->confirmUninstall = 'Are you sure?';
        ...
    }
    
    并在
    displayForm()中使用它

    Configuration::get()
    与config.xml无关,因为它读取数据库表
    dbprefix\u Configuration
    中的字符串值

    例如,要获取默认的车间语言ID:

    $defaultLangID = Configuration::get('PS_LANG_DEFAULT'):
    

    谢谢,但在验证之前,我在原始问题的底部添加了关于
    config.xml
    文件的附加问题。我没有看到自动生成的
    config.xml
    文件。@nyluje config.xml应该在后台加载模块列表时重新生成。至少在1.6中是这样,也许他们在1.7中更改了它,但我对此表示怀疑。
    config.xml
    的内容最终与
    \uu构造()中的
    mymodule.php
    数据匹配。谢谢你的意见,我确认并投票赞成!
    public function __construct() {
        ...
        $this->confirmUninstall = 'Are you sure?';
        ...
    }
    
    $helper->fields_value['confirmUninstall'] = $this->confirmUninstall;
    
    $defaultLangID = Configuration::get('PS_LANG_DEFAULT'):