我想从与他合作过的文件夹结构方面有实际经验的人那里听到您的提示。
来自CodeIgniter ,我现在正在尝试找出创建后端 (CMS)和前端 (frontpage)的最佳方法是什么?
这里有几个应用程序结构,我想对你的批评,考虑到Laravel的实际版本为4.1.28
。
结构1
WEBAPP
BACKEND
app/
bower_components/
local_components/
node_modules/
public/
vendor/
artisan.php
composer.json
composer.lock
CONTRIBUTING.md
Gruntfile.js
package.json
phpunit.xml
readme.md
server.php
FRONTEND
app/
bower_components/
local_components/
node_modules/
public/
vendor/
artisan.php
composer.json
composer.lock
CONTRIBUTING.md
Gruntfile.js
package.json
phpunit.xml
readme.md
server.php
结构2
WEBAPP
app/
bootstrap/
commands/
config/
controllers/
...
views/
filters.php
routes.php
cms/
bootstrap/
commands/
config/
controllers/
...
views/
filters.php
routes.php
bower_components/
local_components/
node_modules/
public/ // This is public for mywebapp.dev
...
index.php
sub/backend // This is public for backend.mywebapp.dev
...
index.php
vendor/
...
server.php
结构3
WEBAPP
app/
controllers/
Backend/
BackendController.php
Frontend/
FrontendController.php
BaseController.php
models/
Backend/
BackendModel.php
Frontend/
FrontendModel.php
BaseModel.php
views/
Backend/
layout.blade.php
Frontend/
layout.blade.php
bootstrap/
bower_components/
local_components/
public/
assets/
backend/
js/
css/
frontend/
js/
css/
index.php
vendor/
server.php
另外,如果您有自己的应用程序结构,也欢迎您共享它。
这确实是个人喜好类型的场景,并且没有真正正确的答案,因为每个人的工作方式都不同。
我倾向于做类似的事情:
app
NameSpace // This is your custom namespace, so for my company it would be AffinityCloud. Then load this in your composer.json using PSR-4 autoloading.
Controllers // I remove the controllers folder from the initial app/controllers location and create a new one in my namespace, also moving the BaseController.php file here too.
Admin // Here go my admin/cms controllers
Frontend // Here go my frontend controllers
Exceptions
Filters
Handlers
Models // I also do the same with the models folder as I do with the controllers folder, making sure my Base.php model file is in there. You'll need to remember to remove the references to the old models and controllers folder from app/start/global.php too, as well as remove these references from your composer.json classmap.
Presenters
Repositories
Services
Utilities
Validators
如上所述,我还将公共/资产下的前端和后端资产拆分到单独的位置。
同样,这就是我喜欢这样做的方式,但是其他人则拥有更干净的解决方案或完全不同的工作方式。 正如我所说,这确实是个人的事情。
我发现对于大多数目的而言,这已经足够分离和组织。
需要牢记的另一件事是,如果您有可以在Laravel之外运行的通用代码,那么也许您应该考虑为其创建一个单独的作曲家程序包。