开发者

Ajax file organization best practices

开发者 https://www.devze.com 2022-12-15 02:50 出处:网络
I have a PHP based web page.Using Ajax, I call PHP routines.Is it a better practice to keep each routine on its own separate file.Or would it开发者_如何转开发 be better to keep them all in one file an

I have a PHP based web page. Using Ajax, I call PHP routines. Is it a better practice to keep each routine on its own separate file. Or would it开发者_如何转开发 be better to keep them all in one file and the divide the file using a $_GET variable.

Example:

if($_GET['AjaxFunction'] == 1) {

...

} elseif($_GET['AjaxFunction'] == 2) {

...

} elseif($_GET['AjaxFunction'] == 3) {

...

}


If the methods have nothing to do with one another then my vote would be to have a separate file for each one.

If the methods are subtle variations of each other then having one file that then looks at the query string or form post data makes more sense.

Either way it's quite subjective. This question is similar to "what's the maximum recommended length of a [file|method|type|whatever]".


I would keep them organized in groups, rather than all together, or all in their own files. For instance, if your have Create, Edit, Delete methods for Messages, put these inside a Messages.php file.

/messages.php?a=create       // Create new message
/messages.php?a=edit&p=12    // Edit message #12
/messages.php?a=delete&p=12  // Delete message #12
0

精彩评论

暂无评论...
验证码 换一张
取 消