0

I'm writing a restful XML API for a university assignment, the spec requires no HTML frontend.

There doesn't seem to be any documentation (or guessable functionality) regarding how to change the default format? Whilst thus far I have created all templates as ...Success.xml.php it would be easier to just use the regular ones and set this globally; I really expected this functionality to be configurable from YAML.. yet I have found some hard coded references to the HTML format.

The main issue I'm encountering is that part of the assessment is returning a 404 in a certain way (not as a 404 :/), but importantly it must always return XML, and the default setup of a missing route is a HTML 404 not XML (so it only works when I use forward404 from an action running via a XML route.

So in summary, is there a way to do this / what class(es) do I have to override?

1 Answer 1

2

Try putting this in factories.yml

all:
  request:
    class: sfWebRequest
    param:
      default_format: xml

That will still need the template names changing though. It will just mean that urls that don't specify a format will revert to xml instead of html.

You can subclass sfPHPView and override the initialise method to affect this (copy paste the initialise method from sfView) - the lines like this need changing:

if ('html' != $format)

You then need to change the view class used ... try this:

http://mirmodynamics.com/post/2009/02/23/symfony%3A-use-your-own-View-class

Sign up to request clarification or add additional context in comments.

3 Comments

Having thought about this, it seems a lot of work to save 3 characters in a filename.... but each to their own!
That was less the concern, more about the defaulting to HTML on any unmatched route.
It was simply the default_format in yaml you suggested that did the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.