如何启动一个大的新ZF2项目? [英] How to start a big new ZF2 project?

查看:119
本文介绍了如何启动一个大的新ZF2项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算用ZF2创建一个新的项目。实际上,我必须升级项目ZF1,但是我决定从头开始。



我的项目很大,已经被翻译成10种不同的语言来自世界各地的志愿者。



我遇到的困难是分析ZF2告诉我要遵循的模块的结构。



该软件允许ISP全球的中小企业管理客户数据库,服务,订单,发票,域名,技术帮助,电子商务,kb等等。



假设ZF2鼓励程序员创建可在其他应用程序中重用的小型模块,并且在所有情况下,我们尽可能地尽可能简化和抽象类的结构,数据库中的许多表项目通过各种外键相互连接,我无法了解如何使用自己的实体文件创建独立模块,同时断开连接



例如:



我的应用程序运行:




  • 客户

  • 订单

  • 发票

  • 付款

  • 消息

  • 私人备注



这是项目的Web界面的屏幕截图:



您可以看到该项目通过嵌入同一项目的各个部分尽可能地显示了法律和秩序情况的概述。最初我想到创建一个单一的模块,但是我需要你的一些建议。



您会建议采用什么策略来采用大型项目​​的结构?

解决方案

我自己目前正在ZF2上开展一个非常大型的项目,并认为成功的关键在于框架提供的模块化。



一些指针我觉得有帮助:




  • 创建抽象/基本模块



    创建基本模块将允许您包含大多数可在任何模块中使用的共享/抽象接口/类。这将意味着基本模块是系统中每个其他模块的依赖。


  • 模块具有相互依赖关系 p>

    某些模块虽然分开,但取决于其他模块的功能(例如,付款可能需要用户信息)。



    您应该仔细考虑这些服务,并确保虽然共享,但不要在每个模块中引入耦合/代码复制。



    我广泛使用了 forward()插件,这允许我从另一个调用另一个控制器动作并建立一个聚合的视图,同时仍然将每个模块封装在自己的模块中。


  • 有效的服务层

    真的是一个一般的MVC设计原则,但是确保您不是在控制器中编码业务逻辑,而是使用注入到控制器中的服务类。


  • 创建服务工厂



    希望使用具体的工厂类(实现 Zend\ServiceManager\FactoryInterface 的类),否则你会很快发现你需要的工厂数量膨胀您的 Module.php ,这些不能像配置一样缓存 - 这意味着性能命中


  • ViewPlugins /控制器插件



    滥用控制器和查看插件的灵活性。这些是非常强大的方式来封装和注入附加的视图/控制器逻辑,而不必扩展现有的类。


  • 表单



    表单可能是一个痛苦,因为有分配的依赖关系,往往需要满足。我认为创建可重用的 fieldets 的功能至关重要,它直接映射到您的域模型(实体)。所有的输入过滤器/ hydrator然后被附加到这个字段集,如果你希望使用它们,你需要做的是将它附加到表单。



    如果你有例如,您可以在 CompanyEditForm CompanyCreateForm CompanyFieldset c>和 CompanyEditForm




我的项目中的一个例子:

  class CompanyCreate extends EntityForm 
{
public function init()
{
$ this-> add(array(
'name'=>'company',
'type'=>'Company\Form\CompanyFieldset',// <重新使用!!
'options'=>数组(
'use_as_base_fieldset'=> true

));
//只有按钮在表单之间有所不同!
$ this-> add(array(
'name'=>'submit',
'priority'=> -100,
'options'=>数组(
'skipLabel'=> true,
),
'attributes'=>数组(
'type'=>'submit',
'class'=>'btn',
'value'=>'创建'

));
}
}

根据您的模块:


我的应用程序运行:客户,订单,发票,付款,留言,私人备注


这似乎是一个开头的自包含模块的好榜单。



我确定有更多的,我会更新,如果我可以想想什么


I am going to create a new project with ZF2 . In fact I'll have to upgrade a project ZF1 but I decided to start from scratch.

My project is very large and has already been translated into 10 different languages ​​by volunteers from all parts of the world.

The difficulty I am having is the analysis of the structure of the modules that ZF2 tells me to follow.

The software allows SMEs in the world of ISPs to manage their customer database , services, orders, invoices , domains , technical assistance , ecommerce, kb, and much more.

Assuming that ZF2 encourages programmers to create small modules reusable in other applications , and that in all cases we try to simplify and abstract as much as possible the structure of classes , many tables in the database of the project are connected to each other through various foreign keys and i can not understand how to create independent modules with their own files of entities and at the same time being disconnected from the project without causing a crash .

For example :

My application runs :

  • Customers
  • Orders
  • Invoices
  • Payments
  • Messages
  • Private Notes

Here is a screenshot of the web interface of the Project :

As you can see the project shows as much as possible an overview of the law and order situation by embedding various sections of the same project . Initially I thought of creating a single module but I need some advice from you.

What strategy would you advise me to adopt a structure of a large project?

解决方案

I myself am currently working on a very large scale project in ZF2 and believe the key to success is embracing the modularity that the framework offers.

Some pointers I feel would be helpful :

  • Create an abstract/base module

    Creating a "base" module will allow you to contain most of the shared/abstract interfaces/classes that could be used in any module. This will mean that the base module is a dependency of each other module within the system.

  • Modules have inter-dependencies

    Some modules, although separated will depend on functionality of other modules (payments may need information on users for example).

    You should carefully think about what these services are and ensure that although they are shared, you do not start introducing coupling/code duplication in each module.

    I make extensive use of the forward() plugin, which allows me to call another controller action from within another and build a aggregated views, while still keeping each module encapsulated in their own modules.

  • An effective service layer

    Really a general MVC design principle, however ensure you are not coding business logic within a controller but rather use 'service' classes injected into your controllers. If you don't you will quickly find it unmanageable.

  • Create Service Factories

    Prefer concrete factory classes (classes implementing Zend\ServiceManager\FactoryInterface) as apposed to closures otherwise you will quickly find that the number of factories you need will bloat your Module.php and these cannot be cached like the configuration - meaning a performance hit

  • ViewPlugins/Controller Plugins

    Abuse the flexibility of controller and view plugins. These are extremely powerful ways to encapsulate and inject additional view/controller logic without having to extend existing classes.

  • Forms

    Forms can be a pain as there is allot of dependencies that tend to need to be met. I think its essential to create reusable fieldsets that map directly to you domain model (entities). All the input filters/hydrators are then attached to this fieldset and should you wish to use them all you need to do is attach it to a form.

    If you have have a CompanyFieldset for instance, you could reuse it in CompanyEditForm and CompanyCreateForm and CompanyEditForm

An example from my project:

 class CompanyCreate extends EntityForm
 {
  public function init()
  {
    $this->add(array(
      'name'    => 'company',
      'type'    => 'Company\Form\CompanyFieldset', // <-- reused!!
      'options' => array(
        'use_as_base_fieldset' => true
      )
    ));
    // Only the button differs between forms!
    $this->add(array(
      'name'     => 'submit',
      'priority' => -100,
      'options'  => array(
        'skipLabel' => true,
      ),
      'attributes' => array(
        'type'  => 'submit',
        'class' => 'btn',
        'value' => 'Create'
      )
    ));
  }
}

In terms to your modules :

My application runs: Customers, Orders, Invoices, Payments, Messages, Private Notes

This seems like a good list of self contained modules to begin with.

I'm sure there is more, i'll update if I can think of anything

这篇关于如何启动一个大的新ZF2项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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