K
K
Ken Jee2017-07-30 13:01:13
Zend Framework
Ken Jee, 2017-07-30 13:01:13

How to organize multiple dependent projects in Zend Framework 3?

I'll start with an analogy. There is such a Yii2 framework, and when it is installed via composer in the advanced option , all the necessary directory structure is immediately deployed.

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

  • The frontend directory is the public part of the site ( frontend/public - the domain mysite.domain looks into it ).
  • Backend directory - here you can immediately hang up, for example, an admin panel ( backend / public directory - the admin.mysite.domain domain looks into it ).
  • The remaining directories are already the engine, etc.

The backend and frontend directories contain their own controllers, models, and views inside...
If we need to add another, let's say, "subproject", for example, a blog, then we simply create the blog directory at the same level where backend and frontend are located, start in new directory with the necessary internal directory structure (for views, controllers, models), associate the blog.mysite.domain domain with the blog/public directory and slightly adjust the framework configs and routing - that's all.
Now the question itself.
How is such a distributed directory structure organized in Zend Framework 3?
There is only one project, but some of its parts (for example, the admin panel, a blog, and something else) should be moved to subdomains. I would like to understand correctly how to organize routing between subprojects and how to separate MVC projects. Of course I read the documentation. But I still can't put it all together. I will be glad to tips and links to information on this issue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Pozdnyakov, 2017-09-19
@Machez

As an example, you create a module, for example Crm, make your home directory on /public of the project.
And in the module config you make such a route

'crm-subdomain' => [
                'type'          => Hostname::class,
                'options'       => [
                    'route'    => 'crm.localhost',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ]
                ],
                'may_terminate' => true,
                'child_routes'  => [
                    'index'          => [
                        'type'    => Segment::class,
                        'options' => [
                            'route'       => '[/:action][/]',
                            'constraints' => [
                                'action' => '[a-z0-9\-]+',
                            ],
                            'defaults'    => [
                                'controller' => Controller\IndexController::class,
                                'action'     => 'index',
                            ]
                        ]
                    ],

By type Hostname, routes will be filtered out, then there is routing through child_routes.

N
novrm, 2017-07-30
@novrm

You need to look towards modules like LosDomain .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question