如何向 Zend URL 映射添加规则并组合多个 MVC 路径? [英] How to add a rule to the Zend URL mapping and compose multiple MVC paths?

查看:31
本文介绍了如何向 Zend URL 映射添加规则并组合多个 MVC 路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是因为我想在同一个项目中开发一个包含多个应用程序的网络平台.

This is because I want to develop a web platform with more than one application in the same project.

在任何 MVC Web 应用程序中,我们都应该有这个默认的 URL 模式:

In any MVC web application we should have this default URL schema:

domain/controller/action/参数

1:在 Zend 中,我可以做什么(在哪些文件中)更改此架构以在 controller 之前添加 application 名称姓名?

1: In Zend, what can I do (in which files) to change this schema to add the application name before the controller name?

预期结果:domain/application/controller/action/parameters

2: 我如何实现这个新 URL 块的结果,即我将分离每个应用程序的 MVC,将共享资源维护在一个单独的目录中?我可以在 Zend autoloader

2: How can I implement the consequences of this new URL block in terms that I will separate the MVC for each application, maintaining the shared resources in a separate directory? What changes may I do in Zend autoloader

预期结果:

/public_html/
/public_html/platform
/public_html/platform/apps

/public_html/platform/apps/base (user interface container)

/public_html/platform/apps/crm
/public_html/platform/apps/crm/model
/public_html/platform/apps/crm/view
/public_html/platform/apps/crm/control
/public_html/platform/apps/crm/public
/public_html/platform/apps/crm/public/css (and etc.)

/public_html/platform/apps/erp
/public_html/platform/apps/erp/model
/public_html/platform/apps/erp/view
/public_html/platform/apps/erp/control
/public_html/platform/apps/erp/public
/public_html/platform/apps/erp/public/js (and etc.)

/public_html/platform/sys
/public_html/platform/sys/core
/public_html/platform/sys/cfg

/public_html/platform/libs/
/public_html/platform/libs/zend
/public_html/platform/libs/template_it
/public_html/platform/libs/custom

推荐答案

我认为这就像拥有实际不同的 ZF2 应用程序一样简单,每个应用程序都在自己的文件夹中,并且在同一级别,一个供应商"文件夹放置所有共享结构(来自 zend、第三方库等).

i think it is as easy as having actual different ZF2 application, every one in its own folder, and in the same level, a "vendor" folder where you put all the shared structure (coming from zend, third party libraries, etc).

然后在供应商文件夹中,我将为您自己的共享代码创建另一个文件夹,包括必须由多个应用程序使用的所有模块,因此您的代码是您自己的库.

Then inside the vendor folder, i would create another folder for your own shared code, including all your modules that has to be used by more than one of the applications, so your code is a library for yourself.

由于您的应用实际上是在域/应用程序中,并且每个人都有自己的配置,因此拥有 domain/application/controller/action/parameters 路由非常简单:您只需创建正常的 controller/action/parameters 路由,因为应用实际上驻留在 domain/application/ 并且路由器不必关心它.

Since your app is actually in domain/application, and everyone has it own config, it is very straightforward to have domain/application/controller/action/parameters routes: you just create your normal controller/action/parameters routes, since the app actually resides in domain/application/ and the router doesnt have to care about it.

正如您所注意到的,另一个问题是自动加载器.您只需要为您的每个应用程序更新对 application.config.php 中共享模块的引用

As you noticed, another problem is the autoloader. YOu just need to update the references to the shared modules inside your application.config.php for everyone of your apps

return array(
    'modules' => array( //....
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php'
        ),
        'config_cache_enabled' => false,
        'cache_dir'            => 'data/cache',
        'module_paths' => array(
            './module',
            '../vendor',//reference to your library modules
        ),
    ),
  //...
);

当然,如果模块不直接位于 vendor/module 内,而是类似于 vendor/libraryname/module,你必须看看你的自动加载系统(Composer 自动加载或其他)并将类或命名空间添加到相应的映射中.

of course, if the modules doesnt reside directly inside vendor/module but something like vendor/libraryname/module, you have to take a look at your autoload system (Composer autoloading or whatever) and add the classes or namespaces to the corresponding maps.

这篇关于如何向 Zend URL 映射添加规则并组合多个 MVC 路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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