Domanda

I have a Phalcon project set up and I have a working implementation of multiple Controller directories. My current directory structure is simple and looks like this:

/controllers
    /admin
        ControllerBase.php
        IndexController.php
    AuthController.php
    ControllerBase.php
    IndexController.php

To get this working, I registered two namespaces:

$loader->registerNamespaces(
    array(
        'App\Controllers' => APP_PATH .'/controllers/',
        'App\Controllers\Admin' => APP_PATH .'/controllers/admin/',
        ...
    ));

While this works, the following 2 issues present themselves when creating a large application with multiple directories:

  1. I need to register a separate namespace for each sub-directory within /controllers. Will this cause any performance issues for, say, 10+ namespaces?
  2. I cannot have 1 universal ControllerBase for all namespaced controllers. Is there any way for all of my controllers, regardless of sub-directory/namespace to inherit from one master base controller?

The main problem I'm having is #2, it seems no matter what I try I cannot have /admin/IndexController.php inherit from /ControllerBase.php. It will only allow me to inherit from the /admin/ControllerBase.php.

È stato utile?

Soluzione

Because it seems to work:

I have multiple namespaces (multiple paths) and many controllers (with or without namespace) that inherits from one ControllerBase (which has no namespace). So it's doable.

As far PHP is able to load your classes you should be able to have only one ControllerBase.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top