I'm trying to clean up the framework I've been working on. Right now, the site consists of the following directories:
Models
Views
Controllers
Helpers (Miscellaneous functions)
Libraries (Universal classes, like library and session management)
Images
Style
Any time a page is called, the router script looks up the associated controller, so thesite.com/login would instantiate Login_Controller at '/controllers/login.php' The problem I'm facing is, the router script itself feels like a type of controller, as does view.php, which handles formatting data to be handled by the appropriate view. But these aren't quite like page controllers, since they control the MVC itself. I'm still somewhat new to this architecture, and I'm curious how someone with more experience would organize this.
Could I classify the router and view controllers as libraries, or would it be better to create a subdirectory inside /controllers called 'pages', or any other ideas? Thanks so much.
Controllers Folder This folder will contain all the Controller classes. MVC requires the name of all the controller files to end with Controller. In our example, the Controllers folder contains two class files: AccountController and HomeController.
Below is a typical folder structure for an ASP.NET web pages web site: The "Account" folder contains logon and security files. The "App_Data" folder contains databases and data files. The "Images" folder contains images. The "Scripts" folder contains browser scripts.
The App_Start folder of MVC application is used to contain the class files which are needed to be executed at the time the application starts. The classes like BundleConfig, FilterConfig, IdentityConfig, RouteConfig, and Startup. Auth etc. are stored within this folder.
It provides three main layers; model, view, and controller. Many developers use MVC as a standard design pattern.
I would suggest you to study a framework's directory structure, such as symfony2 or yii
here is what i chose for mine:
public_html/ (for public files) (should be public, place only index.php in here)
public_html/css/
public_html/images
public_html/js (for your js files, or custom generated ones)
lib/ (for my libs) (should be private)
lib/vendor/ (for 3rd party libs)
application/ (for the whole app) (should be private)
application/class (classes that make the app work such as mainApp, Controller, Model, View, etc...)
application/class/model (all the models)
application/class/view (all the views)
application/class/view/html (templates used by the views)
application/class/controller (all controllers)
application/class/helper (helper functions)
application/class/lib (libs that you develop for the application)
application/template (layout and/or templates for the application)
application/conf (config files)
application/log (log files)
application/cron (scheduled jobs)
application/database (for database migration scripts)
...
You can also use file naming conventions, such as: YourClassName.class.php for clases, YourView.phtml for your views, etc. Check a framework and you'll learn how to structure nicely and app.
I would suggest to follow the Symfony 1.x directory structure. Clear, logical, secure.
Excerpt from book "The definitive guide to Symfony" by Fabien Potencier & François Zaninotto :
apps/
frontend/
backend/
cache/
config/
data/
sql/
doc/
lib/
model/
log/
plugins/
test/
bootstrap/
unit/
functional/
web/
css/
images/
js/
uploads/
I would not call myself an expert but one solution would be to move your 'framework' away from implementation. What I mean is to move your 'router', 'view.php' and other framework classes to some external location which you then include in your index.php or whatever file would be your access point.
Then only content would be in your actual application directory while all framework files would be in a location not accessible via web server.
Just an idea :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With