Welcome Guest, Not a member yet? Register   Sign In
General software design and best practice question
#1

[eluser]Unknown[/eluser]
Hello,

is it possible to have CI output raw XML (or JSON) rather than HTML?

Or, better yet, is it a reasonable use of a framework like CI, or is it too odd a thing to do?

Say, you write an intranet app for internal needs that basically has to fetch records from a database in a more or less clean way. And the GUI is mostly AJAX (or perhaps even a standalone exe) that only forms XMLRPC packets and sends them to the server, that in turn passes the data back to the GUI. (The little business logic there is shall be done on the server, as well.) This is so as to not having to intersperse HTML with PHP, wrap SQL queries into something like a model (in the web-MVC sense) and generally separate the parts from one another.

What are your thoughts on this, in terms of... idk, whatever? (perhaps utility, worthiness or something... can't quite put my finger on it)
#2

[eluser]WanWizard[/eluser]
In our framework we use a central template library to produce all output. Like with the standard CI views, it is fed an array of variables.
In the template library, we check if the URI request was an AJAX call. If so, the contents of the array is returned as JSON, if not, the template is processed to produce the HTML.

This allows the template designer the freedom to create HTML only templates, p.e. with server requests for pagination, or to use ajax calls to fetch the data.
#3

[eluser]Unknown[/eluser]
"-Doctor, everyone ignores me!
-Next, please!"

Smile

WanWizard, thanks for your input.
#4

[eluser]n0xie[/eluser]
The view part of the MVC pattern doesn't mean 'HTML'. It can be anything that could be considered output. If you want your application to only output XML, go for it.

Coincidently, what you are describing now sound a lot like an Service Oriented Architecture. In the java world there is an excellent framework called navajo, which does exactly that: provide data in xml to any number of services. This navajo presentation might be of interest for you. (after all there is nothing stopping you from running navajo and writing a front-end GUI in CI)




Theme © iAndrew 2016 - Forum software by © MyBB