doutang2017 2013-08-16 06:45
浏览 36

PHP MVC文件结构

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条回答 默认 最新

  • doushishi2415 2015-10-22 08:43
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。