SPA에서 사용하기 위해 API를 설정하려고하지만 브라우저에서 나뭇 가지 템플릿을 볼 수 없지만 단지 $ 데이터 응답이라고 생각합니다.Symfony 3 FOSRestBundle 나뭇 가지 - 렌더링하지 않음
어디에서 템플릿을 지정해야합니까? 정확히 어디에 템플릿을 넣어야합니까?
AppBundle/컨트롤러/DefaultController.php
namespace AppBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\View\View;
class DefaultController
{
/**
* @Route("/", name="homepage")
*
*/
public function indexAction(Request $request)
{
$data = 'string';
$view = View::create();
$view
->setData($data)
->setTemplate("default/index.html.twig");
return $view;
}
}
config.yml
#Nelmio CORS
nelmio_cors:
defaults:
allow_origin: ["%cors_allow_origin%"]
allow_methods: ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
allow_headers: ["content-type", "authorization"]
max_age: 3600
paths:
'^/': ~
# FOS REST Bundle
fos_rest:
body_listener: true
format_listener: true
param_fetcher_listener: true
view:
default_engine: twig
view_response_listener: 'force'
exception_wrapper_handler: null
formats:
jsonp: true
json: true
xml: false
rss: false
templating_formats:
html: true
mime_types:
json: ['application/json', 'application/x-json']
jpg: 'image/jpeg'
png: 'image/png'
jsonp_handler: ~
routing_loader:
default_format: json
include_format: false
format_listener:
rules:
- { path: ^/, priorities: [ json, jsonp ], fallback_format: html, prefer_extension: true }
exception:
enabled: true
휴식 응답 (일반적으로 JSON, XML 등)을 원하십니까, 아니면 나뭇 가지보기를 원하십니까? – LBA
엔트리 포인트 즉, mydomain.com/defaultController를 설정하고 싶습니다. - Twig 응답과 거기에서 mydomain.com/todo SPA/React/API - JSON 응답 – Dalli
죄송합니다. – LBA