PHP MVC框架的文件夹结构...我这样做正确吗? [英] Folder structure of a PHP MVC framework... am I doing this right?
问题描述
我目前正在使用自己的PHP框架,需要一些帮助来确定我是否朝着正确的方向前进...
I'm currently working on my own PHP Framework, and I need some help figuring out if I'm going in the right direction or not...
该框架既适合我自己使用,又可以进一步提高我的PHP技能.我遇到了许多问题,通过克服这些问题,我学到了很多东西,并且喜欢能够从无到有地创造出一些东西,所以我宁愿没有看到像仅使用Zend"这样的答案! ;)
The framework is both for my own use and to generally advance my PHP skills further. I've encountered numerous problems that by overcoming them I have learned a great deal, and love being able to create something from nothing, so I'd rather not see answers like "Just use Zend"! ;)
我在Stack Overflow和其他网站上都读了很多文章,但是并不能完全得到我需要的正确答案,因此希望有人能给我一些有用的建议!
I have read a bunch of articles both on Stack Overflow and a bunch of other sites, but can't quite get the right answer I need, so hopefully someone can give me some helpful advice!
我尝试了几种不同的解决方案,但是我最终使自己感到困惑,而且我不确定现在应该朝哪个方向前进!不能完全理解我的意思...
I've tried a few different solutions, but I've just ended up confusing myself and I'm not sure which direction to go now! Can't quite get my head around it all...
理论"框架结构
- .htaccess
- index.php
- private/
- app/
- bootstrap.php
- modules/
- default/
- controllers/
- pages.php
- index.php
- models/
- views/
- admin/
- controllers/
- models/
- views/
- config/
- config.php
- autoloader.php
- lib/
- Some_Library
- Class1
- class1.php
- Class2
- class2.php
- public/
- css
- images
- scripts
详细信息
- index.php 是主文件,每个请求都通过 .htaccess 路由到该文件. 显然,
- private/无法公开访问.
- public/包含所有公共文件.
- app/包含所有特定于应用的代码.
- lib/可能包含Zend或其他库(我也自己工作),可以通过自动加载器调用
- bootstrap.php 是应用程序特定的代码... 我需要这个吗?主要的"index.php"够用吗?.
- 模块/将包含每个模块... 我是否需要模块?.
- default/是默认模块,它将包含大多数请求的MVC(在"admin"不是URL的第一部分时使用).
- admin/是将包含admin部分的MVC的模块.
- index.php is the main file, where every request is routed to with .htaccess.
- private/ can't be accessed publicly, obviously.
- public/ contains all the public files.
- app/ contains all app-specific code.
- lib/ could contain Zend or another library (I'm also working on my own), to be called with autoloaders
- bootstrap.php is the app-specific code... Do I need this? is the main 'index.php' enough?.
- modules/ would contain each module... Do I need modules at all?.
- default/ is the default module that will contain the MVC's for most requests (used when 'admin' isn't the first part of the URL).
- admin/ is the module that will contain the MVC's for the admin section.
无论如何,我的问题...
我认为最好将管理部分与网站的其余部分分开,但这就是我遇到的问题.我已经使上面的结构可以使用它,但是我不确定这是否是最有效的方法.
I thought it would be better to separate the admin section from the rest of the website, but that's where I'm getting stuck. I have made the above structure to work with it, but I'm not sure if this is the most effective way.
如果请求 site.com/videos/view/1/到达我的网站.
If a request site.com/videos/view/1/ comes to my site..
模块:默认 控制器:视频 操作:查看 参数:array('1')
Module: Default Controller: Videos Action: View Params: array( '1' )
,如果请求 site.com/admin/pages/view/1/到达我的网站.
and if the request site.com/admin/pages/view/1/ comes to my site..
模块:管理员 控制器:页面 操作:查看 参数:array('1')
Module: Admin Controller: Pages Action: View Params: array( '1' )
这是解决这个问题的正确方法吗?还是我使它过于复杂并且做了不值得做的事情?
Is this the right way to go about this? Or am I over-complicating it and doing something that's not worth doing?
我的管理部分应该有一个完全独立的应用程序框架吗?我什至需要将管理部分的MVC与其余部分分开吗?
Should I have a completely separate application framework for my admin section...? Do I even need to separate the admin section's MVC's from the rest of it all?
很抱歉出现这么大的问题,只想为您提供尽可能多的信息!随时回答可以做到的任何部分= P
Sorry for the massive question, just wanted to give you as much info as possible! Feel free to answer whichever part you can =P
推荐答案
CakePHP所做的一个管理路由的解决方案是, 您首先定义管理字符串的配置 然后在您的控制器中使用具有特定命名转换的操作
One Solution for admin routing is what CakePHP does, you first define a configuration for the admin string and then in your controller use actions with a specific naming convertion
//Configuration ============================
Configure::write("admin_routing" , true );
Configure::write("admin_prefix" , "admin" );
//Controller ===============================
class MyController extends AppController{
function index(){
//Will map to /mycontroller/
}
function admin_index(){
//Will map to /admin/mycontroller/
}
}
您可以使用路由系统对此进行概括 看看您最喜欢的框架是如何做到的
You can generalize this by using a routing system just look how your favorite framework does it
在另一个音符上
- modules文件夹似乎很简单
- 我同意antpaw,您应该添加一个globals视图和模型文件夹,以便在应用程序之间共享它们
- 我不明白为什么autoloader位于config目录中而不是lib目录的一部分,您也可以将boostrap.php移到config目录中
希望这会有所帮助
这篇关于PHP MVC框架的文件夹结构...我这样做正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!