开发者

What is a good way to organize a PHP website application? [closed]

开发者 https://www.devze.com 2022-12-20 11:51 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_如何转开发
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago.

Improve this question

When doing large projects my code seems to get all over the place. How do you guys organize your code?


You should be using a design pattern; consider starting with MVC.

Strictly following a design pattern will improve the readability of your code base immensely (among other benefits).


Also it is a good idea to use framework (I recommend symfony: http://symfony-project.org). It enforces good files organisation.


Cake PHP is another good framework to use which follows MVC

http://cakephp.org/


I am using below structure and it works fine for me...

--> Class  
--> Action  
--> Middle  
--> Js  
--> Css  
--> inc  

Above is the folder structure i am using. There will be four files for each file.
One file at root. in which all other files will include and other configuration files also included.

In Class Folder:
All the classes for any page will be here. So all DB operation will be here.

In Action File
All the action and method calling will be here. When any form post. First it will check for action in this file. And based on action it will call the function which is in class file.

In middle File

All files in this folder will contain the dynamic HTML of the page. Based on action performed in class files HTML will be displayed from here.

In JS folder
All JS related to project will be here.

In CSS Folder
All CSS related to your project will be here.

In INC Folder
All the common files related to your project will be here. Like
conf.php
sitefunction.php
constant.php


Zend Framework (http://framework.zend.com/) has a powerful MVC framework.


Here's a page that explains some of php code organization: http://net.tutsplus.com/tutorials/php/organize-your-next-php-project-the-right-way/


Since I use CodeIgniter to build the web application in all my projects, I just follow the framework's guideline.

To put a support file (css, js, and image files), I usually split it into 2 directory. For a global support files, I put it in public dir:

public
 |--> css
 +--> images
 `--> js

For a page template, I usually got this from a partner or my client provided it. I will put all the files into styles/front and styles/admin directory. I'm not changing any arrangement of images, js, and css inside these directory, so I can put any updates directly to it.

0

精彩评论

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