问题描述:

In terms of best practices of PHP, is it better practice to write the processing script and the form in the same file or have them separate in different files? How does each scale in proportion to each other for larger projects?

For example, should I write it as:

login.php

<?php

process_form_here();

?>

<form>

<input>

</form>

Or should I write it as:

processor.php

<?php

process_form_here();

?>

login.html

<form>

<input>

</form>

I've been trying to decide for a while between making it more abstract or more condensed... Is there a certain way that most web developers follow?

网友答案:

I think it is generally seen to be a better practice to separate them. Doing so gives you the added benefit of allowing you to guide alternate input routes into the same processor (making it more reusable).

网友答案:

as matter of fact for PHP there is no specific practice such as inline, internel or external you can adapt whichever you are comfortable with. for example for form you can use inline if fields are few. but if you see CMS (wordpress, etc.) file structure you will come to know. think on it see the difference

网友答案:

In terms if scaling it's much better to keep the business logic separate from the view as stated already. This makes things much easier to adapt at a later time and cope with change and expansion. This also allows for reusability.

相关阅读:
Top