PHP MVC file structure

2.6k views Asked by At

How should I structure directories in mvc design pattern in PHP so that I could be able to use the same model and controllers in 'backend' and 'frontend' with different views.

WHAT I HAVE DONE

I am trying to build a website using PHP as server side language and dediced to use MVC design pattern. In my localhost (xampp) I created folder structure like below:

htdocs -- mvc 
           |---- controllers
           |---- models
           |---- views
           |---- library
           |---- system-admin (backend)
               |___ controllers
               |___ models
               |___ views
               |___ index.php (single entry point - backend)
               |___ .htaccess
           |---- index.php (single entry point - frontend)
           |---- .htaccess

I tried to implement basic 'login-system' and created 'Login_Controller' and 'Login_Model' Files.

I GET CONFUSED

How can I be able to use 'Login_Controller' and 'Login_Model' from both backend and frontend while using seperate views for each. What do I mean is , the url for admins to login will be : http://localhost/mvc/system-admin/login/ and the url for site users to login will be : http://localhost/mvc/login/.

I am designing the backend using twitter-bootstrap framework but the design of frontend will be done by some other who may not use the framework that I have used so I need different views. Both backend and frontend will share the files from library. Some Models and Controllers are also shared (such as Login_Model and Login_Controller) and some are not (such as Dashboard_Model and Dashboard_Contoller will be used only in backend I think) .

WHAT I NEED

I need some guid on structuring my directories and judgement on my current file structure. I have never used any design pattern (except singleton :-) ) nor any PHP frameworks so I am not able to make any decision on how to structure files.

1

There are 1 answers

0
Philip Scheer On

for general i would set up your MVC Project the following: Folder Structure /frontend/controllers /frontend/models/ /frontend/views/ /backend/[The same as Frontend] /public/ with Index.php (here the User starts) /libary/ for your Libarys With this structure the User can not access directly the views oder models.