本文介绍了FOS 休息包:无法找到模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到异常:

无法找到模板"

其他类似的问题没有帮助;奇怪的是,它运行良好,然后突然开始给我这个例外.

作曲家:

 "friendsofsymfony/rest-bundle": "0.13.*@dev","jms/serializer-bundle": "0.12.*@dev",

我正在关注 自动路由生成:单个 RESTful 控制器(用于简单资源)

配置:

fos_rest:格式侦听器:真路由加载器:默认格式:json看法:view_response_listener:'强制'序列化器:serialize_null: 真sensio_framework_extra:视图:{注释:假}路由器:{注释:真}

路由:

扇区:类型:休息前缀:/{v}资源:JJ\MainBundle\Controller\SectorsController

控制器:

/*** @RouteResource("扇区")*/类 SectorsController 扩展控制器...公共函数 cgetAction(){返回 $this->getSectorIndustryRepo()->findAll();}
解决方案

我设法通过将侦听器显式设置为 false 来解决此问题:

fos_rest:格式侦听器:假

编辑

这也有效:

fos_rest:格式监听器:首选扩展名:假默认优先级:- json

I get the exception:

The other similar questions didn't help; and weirdly enough it was working fine and then suddenly started giving me this exception.

composer:

I'm following Automatic route generation: single RESTful controller (for simple resources)

config:

fos_rest:
    format_listener: true
    routing_loader:
        default_format: json
    view:
        view_response_listener: 'force'
    serializer:
        serialize_null: true

sensio_framework_extra:
    view:    { annotations: false }
    router:  { annotations: true }

routing:

sectors:
    type: rest
    prefix: /{v}
    resource: JJ\MainBundle\Controller\SectorsController

controller:

/**
 * @RouteResource("Sector")
 */
class SectorsController extends Controller
...
    public function cgetAction()
    {
        return $this->getSectorIndustryRepo()->findAll();
    }
解决方案

I managed to resolve this issue by setting the listener explicitly to false:

fos_rest:
    format_listener: false

EDIT

This also works:

fos_rest:
    format_listener:
        prefer_extension: false
        default_priorities:
            - json

这篇关于FOS 休息包:无法找到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:27