我应该如何在 PHP 的 mvc 设计模式中构建目录,以便我能够在“后端”和“前端”中使用相同的模型和 Controller ,但具有不同的 View 。
我做了什么
我正在尝试使用 PHP 作为服务器端语言构建一个网站,并致力于使用 MVC 设计模式。在我的本地主机 (xampp) 中,我创建了如下文件夹结构:
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
我尝试实现基本的“登录系统”并创建了“Login_Controller”和“Login_Model”文件。
我感到困惑
我如何才能在 backend
和 frontend
中使用“Login_Controller”和“Login_Model”,同时为每个使用单独的 View 。我的意思是,管理员登录的 url 将是:
http://localhost/mvc/system-admin/login/
站点用户登录的 url 为:
http://localhost/mvc/login/
。
我正在使用 twitter-bootstrap
框架设计 backend
但 frontend
的设计将由其他可能不使用该框架的人完成我使用的框架,所以我需要不同的观点。 backend
和frontend
都将共享来自library
的文件。有些模型和 Controller 也是共享的(比如 Login_Model 和 Login_Controller),有些则不是(比如 Dashboard_Model 和 Dashboard_Contoller 我认为只会在后端使用)。
我需要什么
我需要一些指导来构建我的目录和判断我当前的文件结构。我从未使用过任何设计模式(singleton
:-) 除外)或任何 PHP 框架,因此我无法就如何构建文件做出任何决定。
最佳答案
一般来说,我会设置您的 MVC 项目如下: 文件夹结构 /前端/ Controller /前端/模型/ /前端/ View / /后端/[与前端相同] /public/和 Index.php(用户从这里开始) /libary/为你的图书馆 使用这种结构,用户无法直接访问 View 或模型。
关于PHP MVC文件结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18267336/