問(wèn)題描述
我目前正在開(kāi)發(fā)我自己的 PHP 框架,我需要一些幫助來(lái)確定我是否朝著正確的方向前進(jìn)...
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...
該框架既供我自己使用,又可進(jìn)一步提高我的 PHP 技能.我遇到了許多問(wèn)題,通過(guò)克服它們,我學(xué)到了很多東西,并且喜歡能夠從無(wú)到有創(chuàng)造一些東西,所以我不想看到像只使用 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"! ;)
我已經(jīng)閱讀了很多關(guān)于 Stack Overflow 和其他網(wǎng)站的文章,但不能完全得到我需要的正確答案,所以希望有人能給我一些有用的建議!
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!
我嘗試了幾種不同的解決方案,但我最終讓自己感到困惑,我不確定現(xiàn)在該往哪個(gè)方向發(fā)展!無(wú)法完全理解這一切...
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...
'理論'框架結(jié)構(gòu)
- .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 是主文件,每個(gè)請(qǐng)求都通過(guò) .htaccess 路由到這里.
- private/ 顯然不能公開(kāi)訪問(wèn).
- public/ 包含所有公共文件.
- app/ 包含所有特定于應(yīng)用的代碼.
- lib/ 可以包含 Zend 或其他庫(kù)(我也在自己開(kāi)發(fā)),以使用自動(dòng)加載器調(diào)用
- bootstrap.php 是特定于應(yīng)用程序的代碼... 我需要這個(gè)嗎?主要的'index.php'就夠了嗎?.
- modules/ 將包含每個(gè)模塊... 我需要模塊嗎?.
- default/ 是包含大多數(shù)請(qǐng)求的 MVC 的默認(rèn)模塊(當(dāng)admin"不是 URL 的第一部分時(shí)使用).
- 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.
無(wú)論如何,對(duì)于我的問(wèn)題...
我認(rèn)為將管理部分與網(wǎng)站的其余部分分開(kāi)會(huì)更好,但這就是我陷入困境的地方.我已經(jīng)制作了上述結(jié)構(gòu)來(lái)使用它,但我不確定這是否是最有效的方法.
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.
如果請(qǐng)求 site.com/videos/view/1/ 來(lái)到我的網(wǎng)站..
If a request site.com/videos/view/1/ comes to my site..
模塊:默認(rèn)控制器:視頻操作:查看參數(shù):數(shù)組('1')
Module: Default Controller: Videos Action: View Params: array( '1' )
如果請(qǐng)求 site.com/admin/pages/view/1/ 來(lái)到我的網(wǎng)站..
and if the request site.com/admin/pages/view/1/ comes to my site..
模塊:管理員控制器:頁(yè)面操作:查看參數(shù):數(shù)組('1')
Module: Admin Controller: Pages Action: View Params: array( '1' )
這是解決這個(gè)問(wèn)題的正確方法嗎?或者我是否過(guò)度復(fù)雜化并做了一些不值得做的事情?
Is this the right way to go about this? Or am I over-complicating it and doing something that's not worth doing?
我的管理部分是否應(yīng)該有一個(gè)完全獨(dú)立的應(yīng)用程序框架...?我什至需要將管理部分的 MVC 與其他部分分開(kāi)嗎?
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?
抱歉問(wèn)了這么大的問(wèn)題,只是想為您提供盡可能多的信息!隨意回答你能回答的部分=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
推薦答案
一個(gè)管理路由的解決方案是 CakePHP 所做的,您首先為管理字符串定義一個(gè)配置然后在您的控制器中使用具有特定命名轉(zhuǎn)換的動(dòng)作
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/
}
}
您可以使用路由系統(tǒng)對(duì)此進(jìn)行概括看看你最喜歡的框架是怎么做的
You can generalize this by using a routing system just look how your favorite framework does it
另外一點(diǎn)
- modules 文件夾似乎不需要
- 我同意 antpaw 您應(yīng)該添加一個(gè)全局視圖和模型文件夾,以便在應(yīng)用程序之間共享它們
- 我不明白為什么自動(dòng)加載器在 config 目錄中而不是 lib 目錄的一部分,您也可以將 boostrap.php 移動(dòng)到 config 目錄
希望能幫到你
這篇關(guān)于PHP MVC 框架的文件夾結(jié)構(gòu)......我這樣做對(duì)嗎?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!