Prestashop 1.7.7.5:FrameworkBundleAdminController:$this->module->getPathUri() returns 一个错误

Prestashop 1.7.7.5: FrameworkBundleAdminController: $this->module->getPathUri() returns an error

在我管理模块的控制器的listMappingsAction动作中,我想显示一个Vue.JS模板,传递两个需要调用$this->module->getPathUri()赋值的变量:

<?php
namespace XYZ\Controller;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;


class AutomatizedMappingController extends FrameworkBundleAdminController
{

     /**
     * @AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.")
     */
    function listMappingsAction() {
        return  $this->render('@Modules/XYZ/views/templates/admin/app.html.twig', [
            'XYZ' => [
                'pathApp' => $this->module->getPathUri() . 'views/js/app.js',
                'chunkVendor' => $this->module->getPathUri() . 'views/js/chunk-vendors.js',
            ]
        ]);
    }
}

使用 $this->module->getPathUri() 导致显示此错误:

Attempted to call an undefined method named "getPathUri" of class "XYZ\Controller\AutomatizedMappingController". [Symfony\Component\Debug\Exception\UndefinedMethodException 0]

我可以调用什么来让它工作?文档没有提到这个用例... https://devdocs.prestashop.com/1.7/modules/concepts/templating/vuejs/faq/#how-to-send-data-from-symfony-controller-to-vuejs

首先你需要知道模块和管理控制器之间是有区别的。您不能调用 $this->module->getPathUri(),因为您没有使用 extends ModuleAdminControllerextends ModuleFrontControllerextends Module ...

所以你只能调用 $this->module 如果你实际使用模块中的文件。

因为我不知道你想走哪条路,所以我给你传递了一些你可能会用到的变量。

$this->module->name              = crezzurmodulename
$this->module->getLocalPath()    = C:\yourstore/modules/crezzurmodulename/
$this->module->getPathUri()      = /yourstore/modules/crezzurmodulename/
_MODULE_DIR_                     = /yourstore/modules/
_PS_MODULE_DIR_                  = C:\yourstore/modules/
__DIR__                          = C:\yourstore\modules\crezzurmodulename\controllers\front
_PS_CAT_IMG_DIR_                 = C:\yourstore/img/c/
_PS_PROD_IMG_DIR_                = C:\yourstore/img/p/
_PS_TMP_IMG_DIR_                 = C:\yourstore/img/tmp/
_PS_ROOT_DIR_                    = C:\yourstore
_PS_CACHE_DIR_                   = C:\yourstore/var/cache/dev\
_PS_BASE_URL_                    = http://127.0.0.1
__PS_BASE_URI__                  = /yourstore/
_PS_TRANSLATIONS_DIR_            = C:\yourstore/translations/
_PS_BASE_URL_SSL_                = http://127.0.0.1 or https://127.0.0.1
_PS_DOWNLOAD_DIR_                = C:\yourstore/download/
_PS_COL_IMG_DIR_                 = C:\yourstore/img/co/
_PS_SHIP_IMG_DIR_                = C:\yourstore/img/s/
_PS_UPLOAD_DIR_                  = C:\yourstore/upload/