Page 2 of 2

Re: MVC, Forms, and JavaScript

Posted: Sun Aug 10, 2008 1:53 pm
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.

Re: MVC, Forms, and JavaScript

Posted: Sun Aug 10, 2008 8:14 pm
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).

Re: MVC, Forms, and JavaScript

Posted: Mon Aug 11, 2008 1:02 pm
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.

Re: MVC, Forms, and JavaScript

Posted: Mon Aug 11, 2008 2:06 pm
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.

Re: MVC, Forms, and JavaScript

Posted: Mon Aug 11, 2008 6:56 pm
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.