douche3791 2018-09-03 01:00
浏览 48
已采纳

shopware Controller没有获得模板

i am trying to create a controller and show something on a view however it ooks like something is wrong. i created a plugin with the following files

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/Resources/views/frontend/routing_demonstration/index.tpl

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

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

i also have the config.xml,plugin.xml and SwagStartup.php in there right places.

when i uncomment the hello world i will see the text in the browser when i call the controller however when i comment it out then

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

so what could be the issue and am i missing anything? i am using shopware version 5.4.6 and following this did not help either

  • 写回答

2条回答 默认 最新

  • dongzhuo3376 2018-10-12 03:20
    关注

    Just to update incase someone gets the same issue. my problem was here, i think its because i was tired i could not see it.

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

    that should have been

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

    it should be __DIR__ and not _DIR_

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部