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