|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
wvengen Smarty n00b
Joined: 29 Nov 2010 Posts: 2
|
Posted: Tue Nov 30, 2010 11:15 am Post subject: New plugin: ForSQL -- SQL-based for-loop |
|
|
I'd like to announce a new plugin that allows one to put SQL SELECT statements directly in a template, which I've been using for the past year and thought it would be time to share. Hope it's useful to others too.
For more information, see http://willem.engen.nl/projects/smarty/. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Nov 30, 2010 2:45 pm Post subject: |
|
|
Bad idea, SQL in templates breaks the separation of presentation from business logic. Do SQL in PHP and assign the *results* to the template.
See here:
http://www.smarty.net/best_practices |
|
Back to top |
|
wvengen Smarty n00b
Joined: 29 Nov 2010 Posts: 2
|
Posted: Tue Nov 30, 2010 4:15 pm Post subject: |
|
|
Whoops, I think I missed that section, thanks.
Still in the case of just viewing information (no logic), I find myself writing a lot of boiler-plate code in PHP that doesn't do much besides propagating the results from the database query to the template. This seems to me a lot cleaner.
Reactions to the issues mentioned in the best practices:
1) "SQL statements are business logic" -- not if it's just a SELECT statement; views should be used to get away with foreign keys, for example.
2) "designer should not need to know anything about SQL or where the content comes from" -- agree with the where the content comes from, but in the prototyping phase it can be really handy to just cross the boundary a little.
3) "would easily break the SQL" and other errors -- security is an issue, but this could be made more robust by some restrictions and automatic quoting.
In the prototyping phase design need not be fixed, and the strict MVC separation is unsuitable. When design is fixed, strict MVC separation is key to consistent and maintainable code.
My conclusion: useful for prototyping, bad for production.
Does that make sense, or should this be banned from the face of the earth? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Nov 30, 2010 4:33 pm Post subject: |
|
|
I don't see a point in doing this for prototyping, you still need to build the separation correctly to go to production anyways. This does not offer anything useful, only encourages improper separation. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|