如何构造MVC应用程序作曲家风格? [英] How to structure MVC application composer style?

查看:56
本文介绍了如何构造MVC应用程序作曲家风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于制作MVC网络应用程序的初期。我想尝试做作曲家的风格。到目前为止,这是我的目录结构:

I'm in the very early stages of making an MVC web application. I want to try and do things composer style. Here is my directory structure so far:

public_html
    |-vendor
    |   |-MyVendorName
    |   |   |-DomainObjectClass.php

这就是我存储域对象的地方。

So that's where I am storing domain objects.

我也在尝试尽可能接近MVC的方式来完成MVC,这是对

I'm also trying to do MVC as close as I can to the way it is done in the answer to this question

我有点卡住的地方是将模型,控制器放在哪里,视图,服务,DataMappers等。我应该创建MyVendorName的子目录(例如MyVendoreName / DomainObjects / DomainObjectClass.php和MyVendorName / Services / SomeServiceClass.php等),还是将目录与供应商分开,称为类或src,还是更明智?

Where I am a bit stuck is where to put the Model, Controller, View, Services, DataMappers etc. Should I make subdirectories of MyVendorName (eg MyVendoreName/DomainObjects/DomainObjectClass.php and MyVendorName/Services/SomeServiceClass.php etc) or would it be wiser to make a directory separate from vendor called classes or src or something and do MVC stuff there?

编辑:?每个人都说供应商是针对第三方库的,我明白了。但是,我编写域对象的方式与MVC方面却是脱钩的。实际上,他们甚至都不知道自己是MVC应用程序的一部分。它们可以很容易地在其他项目中重用(我打算这样做)。因此,将其放在src /或app /

Everyone is saying that vendor is for third party libs, I get that. But the way I am writing my domain objects is very decoupled from the MVC side of things. In fact, they do not even know they are part of an MVC app. They could very easily be reused in other projects (I intend to do this). So it seems illogical to me to put it in src/ or app/

推荐答案

上对我来说似乎不合逻辑。正确答案。但是,我将分配以下提示:

This is an extremely debatable topic and there's no one right answer. However, I'd dispense the following hints:


  • 供应商目录用于第三方依赖项,您不应该在其中编写自己的代码

  • 将您自己的代码放入 src lib 目录,在 vendor 目录旁边

  • 这两个目录都不应该在公共目录中webroot文件夹; webroot应该是一个单独的目录,仅包含CSS和JS文件等公共服务文件,webroot之外的任何其他内容

  • 在名称空间中构造类名称

  • 从名称空间开始遵循目录结构

  • 明确具有 MyVendorName\Controller MyVendorName\模型等很有意义

  • 结构很有意义,例如 MyVendorName\Model\DomainObjects\Foobar\Subclass 有意义

  • the vendor directory is for third party dependencies, you should not be writing your own code in it
  • put your own code in a src or lib directory, next to the vendor directory
  • neither of these directories should be in the public webroot folder; the webroot should be a separate directory containing only publicly served files like CSS and JS files, anything else is outside the webroot
  • structure your class names in namespaces
  • from the namespaces follows the directory structure
  • explicitly having a MyVendorName\Controller, MyVendorName\Model etc. makes sense
  • structure as deeply as makes sense, e.g. MyVendorName\Model\DomainObjects\Foobar\Subclass makes sense

这篇关于如何构造MVC应用程序作曲家风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆