在 PS 1.7 中,我的后台未显示渲染视图 [英] Rendered view is not displaying in my back office in PS 1.7

查看:86
本文介绍了在 PS 1.7 中,我的后台未显示渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在安装模块时创建的后台选项卡中创建一个视图.我的模块添加了这样的标签:

I am trying to create a view in the back office tab that I created in the installation of my Module. My Module adds the tab like this:

protected function _installTabs()
{
    if(!$tabId = \Tab::getIdFromClassName('IezonPortfolio')) {
        $tab = new \Tab();
        $tab->class_name = 'IezonPortfolio';
        $tab->module = $this->name;
        $tab->id_parent = \Tab::getIdFromClassName('ShopParameters');
        $tab->active = 1;
        
        foreach (Language::getLanguages(false) as $lang):               
           $tab->name[(int) $lang['id_lang']] = 'My Portfolio';
        endforeach;
        
        return $tab->save();
    }
    
   new \Tab((int) $tabId);
   return true;
}

这很好用,我可以导航到我的商店参数并单击我的投资组合选项卡.我遇到的问题是它是空白的.我的 ModuleAdminController 看起来像这样:

This works fine and I can navigate to my Shop Parameters and click the My Portfolio tab. The issue I'm having is that it is blank. My ModuleAdminController looks like this:

class IezonPortfolioController extends ModuleAdminController {
    private $_module;
    
    public function __construct()
    {
        $this->bootstrap = true;
        parent::__construct();
        $this->_module = \Module::getInstanceByName('iezonportfolio');
    }
    
    public function indexAction()
    {
        return $this->render('@Modules/iezonportfolio/views/templates/admin/display.html.twig', array(
            'contents_iezonportfolio' => $this->_module->selectAll()
        ));
    }
}

我的 display.html.twig 中只有 test 以查看它是否会输出它没有输出的任何内容.在查看文档时它没有提及任何内容除了使用 render 函数并返回它.任何帮助,将不胜感激.我只是得到一个空白标签.

My display.html.twig just has test in it to see if it would output anything which it didn't. On looking at the Docs it doesn't mention anything other than using the render function and returning it. Any help would be appreciated. I just get a blank Tab.

在查看了一些预安装的模块并将它们引用到文档后,我发现我缺少路由配置.我的控制器位于记录的目录设置中:iezonportfolio/controllers/admin/iezonportfolio.php 所以我的路线是这样的:

After looking at some of the pre-installed modules and referencing them to the Docs, I saw that I was missing my route configuration. My Controller is in the documented directory set-up: iezonportfolio/controllers/admin/iezonportfolio.php so I made my route like this:

iezonportfolio:
  path: iezonportfolio
  methods: [GET]
  defaults:
    _controller: 'IezonPortfolio\Controllers\Admin\Controller::indexAction'
    _legacy_controller: 'IezonPortfolioController'
    _legacy_link: 'IezonPortfolioController:index'

这还没有修复空白显示,所以我试图更深入地研究其他一些模块,现在更新了我的 display.html.twig 来显示这个:

This has still not yet fixed the blank display so I tried to dig deeper into some other modules and have now updated my display.html.twig to show this:

{% extends '@PrestaShop/Admin/layout.html.twig' %}

{% block content %}
  Test
{% endblock %}

这也没有修复空白显示.我希望这个添加对未来的观众有用.

This did not fix the blank display either. I hope this addition is useful for future viewers.

推荐答案

这不是现代控制器的工作方式,您正在扩展遗留的 ModuleAdminController,请看这里:

This is not how the modern controllers works, you are extending legacy ModuleAdminController, take a look here:

https://github.com/PrestaShop/example-modules

您有很多模块示例,以下是其中一个模块的一小段:

you have a plenty of module examples, here's a little snippet from one of those modules:

declare(strict_types=1);

namespace PrestaShop\Module\DemoControllerTabs\Controller\Admin;

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\HttpFoundation\Response;

class MinimalistController extends FrameworkBundleAdminController
{
    /**
     * @return Response
     */
    public function indexAction()
    {
        return $this->render('@Modules/democontrollertabs/views/templates/admin/minimalist.html.twig');
    }
}

我建议您考虑是否要使用现代控制器.这取决于您是否想出售您的模块、在客户项目中使用它等.

I recommend you to think wether you want to use, or not, modern controller. It depends on wether you want to sell your module, use it in client projects etc.

这篇关于在 PS 1.7 中,我的后台未显示渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆