如何在插件webroot中加载xml文件

时间:2015-05-29 12:03:05

标签: cakephp plugins components cakephp-3.0

我正在使用cakephp-3.0

在插件的组件中,我想在插件webroot中加载XML文件。

simplexml_load_file('RangeMessage.xml')

无法找到该文件。使用

调试路径
debug(realpath(''));

说实际目录是/path/to/app/webroot。 我的xml文件位于/path/to/app/plugins/myPlugin/webroot 那么如何在不使用绝对路径的情况下找到文件呢?

1 个答案:

答案 0 :(得分:0)

您可以使用Plugin::path()来检索插件的绝对路径,因此您无需对其进行硬编码。

Plugin::path('YourPlugin') . 'webroot' . DS . 'RangeMessage.xml'

另请参阅 API > Cake\Core\Plugin::path()

相关问题