MVC, Forms, and JavaScript

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

User avatar
VirtuosiMedia
Forum Contributor
Posts: 133
Joined: Thu Jun 12, 2008 6:16 pm

Re: MVC, Forms, and JavaScript

Post by VirtuosiMedia »

acidHL wrote:To echo what some of the folks have already said... I don't think forms are particularly a special case, you just need a flexible helper for outputting validation errors. I tend to write form-heavy applications on CodeIgniter and don't really have a problem with code separation.

If you wanted to be pedantic about no PHP in your view then you could surely solve the problem with clever use of a template engine?
I don't think I have a problem with PHP in the view, I was just under the (misguided) impression that a MVC goal was to have as little PHP in it as possible. I've played around with Smarty a little bit, but I didn't really like it very much because, while it doesn't put any PHP the template, it still has a lot of non HTML markup and logical expressions. To me, that seems like it's just adding another layer of complexity and overhead for very little benefit. You have to learn a new syntax and it really doesn't look all that much different that PHP anyways.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: MVC, Forms, and JavaScript

Post by alex.barylski »

I don't think I have a problem with PHP in the view, I was just under the (misguided) impression that a MVC goal was to have as little PHP in it as possible
That is what confused me too. Mostly because of everything I read was written by developers coming from desktop development where the view is generated by native code not HTML.
I've played around with Smarty a little bit, but I didn't really like it very much because, while it doesn't put any PHP the template, it still has a lot of non HTML markup and logical expressions
Honestly. Don't! Unless you have a compelling reason to do so...using alternative syntax in your HTML/PHP templates results in better code and easier to read for everyone not just Smarty developers.

I tried for ages to figure out a way to remove logic from templates completely...I had one idea which was damn close but would fail with really complex designs -- which is probably a sign your GUI needs to be simplified but...if it doesn't work 100% don't bother cause something is wrong.

Keep the code in your templates specific to templates...so no querying the database...do that in your model and pass the model results to the template. I have heard some are OK with actually querying the model from within the view/template (probably the former).
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: MVC, Forms, and JavaScript

Post by ghurtado »

Hockey wrote:.. using alternative syntax in your HTML/PHP templates results in better code and easier to read for everyone not just Smarty developers.
If by "alternative syntax" you mean Smarty specific syntax, I couldn't disagree more. How could you say that Smarty is easier to read than PHP? In my opinion it just jumbles the symbols around, requiring a similar structure with confusing syntactical differences. Not only that, but Smarty is only one of many template systems, most of which reinvent the template syntax over and over again in their image.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MVC, Forms, and JavaScript

Post by Christopher »

The one reason to not allow people to use PHP for view/templates is security. If you allow untrusted users to use PHP, you are giving them access to your server. I usually just use HTML templates in that case.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: MVC, Forms, and JavaScript

Post by alex.barylski »

If by "alternative syntax" you mean Smarty specific syntax, I couldn't disagree more. How could you say that Smarty is easier to read than PHP? In my opinion it just jumbles the symbols around, requiring a similar structure with confusing syntactical differences. Not only that, but Smarty is only one of many template systems, most of which reinvent the template syntax over and over again in their image.
Ummm dude...I think you need the manual a little more. ;)

http://ca3.php.net/alternative_syntax
The one reason to not allow people to use PHP for view/templates is security. If you allow untrusted users to use PHP, you are giving them access to your server. I usually just use HTML templates in that case.
What he said.
Post Reply