XSLTs for a better MVC model?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

XSLTs for a better MVC model?

Post by Jammerious »

Hi,
I am not yet too deep into my project and I am starting to like the idea of getting more and more things done with XMLs and XSLTs.
Dropping smarty ended up with my view looking quite nasty, so maybe I could do the whole thing with XML sources and XSL transformations.
I enjoy doing stuff to the tiniest of details so I actually like writing well-formed code.
So I am thinking, XSLTs must be the best way, from a respected institution, to enforce the separation of V and C.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: XSLTs for a better MVC model?

Post by alex.barylski »

Or you could use a PHP alternative syntax so the widest possible audience has a clue as to whats going on. :P

XSLT looks neat, admittedly I've only read about it, never really acted on it. Tony Marston promotes the idea like the gospel, so that kind of scares me away. :lol:

I think it's the neatest when you want to easily switch your view output (client view) from XHTML to PDF, then it makes sense, as writing a PHP alternative syntax template for PDF would probalby be really disgusting.

Cheers,
Alex
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: XSLTs for a better MVC model?

Post by pickle »

Basically you're wanting to use XML & XSLT as a way to enforce separation of business and display logic. That can quite easily be done with just PHP - and likely with more flexibility.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: XSLTs for a better MVC model?

Post by Eran »

I'd agree with Pickle, XML is very verbose and unflexible. Instead of smarty, try a more OO templating/view system, such as Savant or Zend_View. I wrote an article about the approach those systems take a while ago, which you might find relevant
Theory?
Forum Contributor
Posts: 138
Joined: Wed Apr 11, 2007 10:43 am

Re: XSLTs for a better MVC model?

Post by Theory? »

The thing about XML though is that its easy for systems to read. As systems become more dispersed among multiple servers, some not even local to a given cluster, the less time it takes to process any input, the better. If your application's views will need to be parsed by something other than a browser, than building an app that outputs to XML would greatly leverage your app in the long run since all it would take is a nice simple transformation to make your output readable. Otherwise, stick with what everyone else is saying.
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

Re: XSLTs for a better MVC model?

Post by Jammerious »

Thank you all,
taking your suggestions into account, I now plan to do something like pytrin explained in his article (nice blog, btw, I subscribed), however I'll try and make some modules with XML/XSL, like frontend news and other clearly structured parts. This would allow easy deployment of RSS sources and falls along nicely with memcached (can't wait to try this one out).

I guess I'll eventually realise what do you mean with this approach not being flexible. Other than that I don't see any arguments against XSLT. I don't know what do you mean with XML being too verbose, it's not like anyone is going to have to write any sources by hand. Each data object, if well made, can be easily represented with a XML element through a toXml() method (where the only verbosity needs to be?).
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

Re: XSLTs for a better MVC model?

Post by koen.h »

Another thing that may come into play is that the library for XSLT (libxslt) is installed but not enabled by default. If you would want to distrubute a project using this as open source, many people will not be able to use it.
Post Reply