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


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

domain/controller/action/parameters

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

Expected Result: domain/application/controller/action/parameters

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

Expected Result:

/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
有帮助吗?

解决方案

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.

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.

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
        ),
    ),
  //...
);

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top