shopware Controller无法获取模板

时间:2018-09-03 09:00:57

标签: php smarty shopware

我正在尝试创建一个控制器并在视图上显示某些内容,但是看起来有些错误。我用以下文件创建了一个插件

SwagStartup / Controllers / Frontend / RoutingDemonstration.php

<?php
class Shopware_Controllers_Frontend_RoutingDemonstration extends Enlight_Controller_Action
{
    public function preDispatch(){
      $this->view->addTemplateDir(_DIR_.'/../../Resources/views');
    }

    public function indexAction()
    {
        //die('Hello world test !');
    }
}

SwagStartup /资源/视图/前端/routing_demonstration/index.tpl

{extends file="parent:frontend/index/index.tpl"}

{block name="frontend_index_content"}
    <h1>Hello World</h1>
{/block}

我也有config.xml,plugin.xml和 SwagStartup.php在正确的位置。

当我取消对世界的注释时,我在调用控制器时会在浏览器中看到文本,但是当我注释掉然后

Oops! An error has occurred!
We have been informed about the problem and try to solve it. Please try again within a short time.

那可能是问题所在,我错过了什么吗? 我正在使用5.4.6版的购物软件 和following this都没有帮助

2 个答案:

答案 0 :(得分:0)

能否请您添加详细的错误消息?消息“糟糕!...”仅是用户输出,而不是技术错误消息。

https://en-community.shopware.com/Debugging-in-Shopware_detail_1912.html

我在测试插件中做了同样的操作:https://github.com/mnaczenski/ControllerTest/blob/master/Controllers/Frontend/Testcontroller.php

这可以正常工作并呈现插件模板。

答案 1 :(得分:0)

仅在有人遇到相同问题时进行更新。我的问题在这里,我想是因为我累了我看不到它。

$this->view->addTemplateDir(_DIR_.'/../../Resources/views');

本来应该

$this->view->addTemplateDir(__DIR__.'/../../Resources/views');

应该为__DIR__,而不是_DIR_