3

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Lekhnath
  • 4,532
  • 6
  • 36
  • 62
  • 1
    `controllers/admin , controllers/users` . Then you can put something in your library to check the role of the user then redirect on the corresponding controller. For scripts and css you can put it in `mvc/assets` – Drixson Oseña Aug 16 '13 at 06:49
  • 1
    Backend and frontend are separated modules so they should have separated `controllers`, `views`, etc. folders. But you can have common `models` and `libraries`. – Elon Than Aug 16 '13 at 06:59
  • How can I check the role before login. If someone is registerd as admin then he will go to `http://localhost/system-admin/login` and others will go to `http://localhost/login` for login. My task is to show different login pages (views) using the same controller (Login_Controller). and how? – Lekhnath Aug 16 '13 at 07:00
  • Thankyou for your comment , I will try with multiple controllers as you both suggested, thanks. – Lekhnath Aug 16 '13 at 07:12
  • Here's a hint: don't put in the `DOCUMENT_ROOT` files that you do not expect users to open. Most of your application should be located outside `DOCUMENT_ROOT`. Also, model is not a class. Model is a layer. – tereško Aug 16 '13 at 07:49
  • @tereško thanks for comment but I could not really understand what you are trying to say. – Lekhnath Aug 16 '13 at 07:54
  • @Lekhnath , do you not know what `DOCUMENT_ROOT` is? Or was the "model part" the confusing bit? – tereško Aug 16 '13 at 08:01
  • @tereško I think normally `public_html` are the document roots, but in localhost (xampp) I have no idea. Models and Controllers both are confusing me. As many things are new to me (the `application` directory, the `bootstrap.php` router, `public` , `library`, `autoloader` and recent the `DOCUMENT_ROOT`) , I think they are bit tricky to me. Please keep me alive by providing some tips and some tutorials with `backend` `frontend` `themes` using PHP MVC .. – Lekhnath Aug 16 '13 at 08:13
  • Then start with [this list](http://stackoverflow.com/a/16356866/727208) of materials. Also, MVC has nothing to do with themes. – tereško Aug 16 '13 at 08:16

1 Answers1

-1

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.

Philip Scheer
  • 241
  • 1
  • 2
  • 12