forms/heredocs versus Ajax versus....? What are 'Best Practices' for interactive website development?
I am unsure about what to use to develop a site for the startup gang I'm working with. I'm tasked with getting the initial version of the site going.
I am familiar with 2 ways to make a site interactive and responsive to asynchronous user interaction on the site:
1) Ajax
2) using heredoc and forms technique of calling back to the same PHP file to handle a user's interactions on a form, such as here:
echo <<<_END
<form action="sqltest.php" method="post">
Enter stuff, okay go for it: <input type="text" name="someInputField" />
<input type="submit" value="ADD STUFF NOW" />
</form>
_END;
What is the most common-in-industry approach for dynamic website coding? Methinks that perhap neither Ajax nor the heredoc is still the #1 choice for site developers -- I need to make this code up-to-date because when we hire a paid developer to take over development we DON'T want the guy to tell us "you'd be better off if I re-write the site using 'X'.
Right now I'm considering using Ajax and XAMPP. But I don't want the hotshot coder we eventually hire to say "Sure Ajax works, but this technique 'X' is the 'Bes开发者_C百科t Practice' in the industry these days.'
Trying to start our site's initial code base here with the current 'Best Practices' but I don't know what the best practices are...?
I'm a bit unsure as to what you mean by the 'heredoc' approach. Also, I think this question would be better accommodated on programmers.
At any rate, to answer your question (which is a bit too open ended).
Try to at least organize your project into distinct parts. Use an MVC based approach. You don't need to go full on framework, but layering on a template framework like Smarty will help you a lot. Or you can write your own light layer as well.
As for your front end, code your site to work with basic functionality. Make sure everything works without Ajax/JS. Then start layering on increasing interactivity by using unobtrusive javascript techniques. This will ensure your site gets the widest possible audience while being able to leverage new technologies and methods. You can also use some HTML5 and CSS3 in there as well.
Make sure you use a coding standard and stick to it. If you use a framework, they usually encourage you to stay in character when coding in any case. Lots of popular frameworks are available if you go the framework route. Including, but not limited to Zend, CakePHP, Codeigniter, symfony and many more.
And feel free to use JS libraries to do all the legwork for you. Some of the most popular are jQuery, mootools and prototype
Ajax is fine but consider browsers with no JS (or JS turned OFF) - if You implement AJAX solution You still have to implement standard form submitting...
I've never used heredoc for site developing, instead of this I recommend using of some MVC / MVP frameworks or just the MVC/MVP pattern for application.
These days You can find a lot of frameworks that are good for that or You can use poor PHP and implement in that way...
My approach while using object oriented programming in PHP is to have a class for a form with init method for form and form fields initialisation, view method for displaying of form and a submit method for post data manipulation...
In MVC You'd have to have at least two classes for this -> one for creating of the form, second for data manipulation, one view (.tpl, .html or .phtml template) and maybe a model class when data is stored somewhere...
But this question could be debated for hours with o lots of opinions and argues and with no definitive result...
精彩评论