rest - Controller not rendering the template -


i using fos bundle implement rest api in symfony.

i have controller called termscontroller in have implemented routes rest api.

the routes put,get,post , delete return array want function newtermaction (whose route /terms/new ) render template.

that route should direct form il make post call

but template not getting rendered , output raw html code

here function

public function newtermsaction()   {      return $this->render('default/termform.html.twig');   } 

config.yml file

sensio_framework_extra:     view:   {   annotations: false }     router: {   annotations: true }  fos_rest:     param_fetcher_listener: true     body_listener: true     format_listener: true     view:         view_response_listener: 'force'         formats:             xml: true             json : true         templating_formats:             html: true         force_redirects:             html: true         failed_validation: http_bad_request         default_engine: twig     routing_loader:         default_format: json 

i have tried using not working

$view = $this->view()             ->settemplate("termsbundle:default:termform.html.twig");     return $this->handleview($view);  error : attempted call undefined method named \"view\" of class 

try that:

public function newtermsaction(){     $view = $this->view(null, 200)         ->settemplate('default/termform.html.twig')     ;      return $this->handleview($view) } 

you may have tweak config. take @ this part of docs more details.

edit: issue controller did not inherit fosrestcontroller, correct way it.

in addition, don't forget add html format @ end of request, or controller try render default format set in config, e.g. :

terms/new.html 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -