We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

sub folder in controller directory in multiple

Hi,

I have an API folder in controller directory (frontend)

Just an example:

apps
 |-- frontend
 |...     |--  controllers
 |...     |...      |--  api
 |...     |...      |....     `--  API1Controller.php
 |...     |...      |....     `--  API2Controller.php
 |...     |...      |....     `--  API3Controller.php
 |...     |...      `--  Posts1Controller.php
 |...     |...      `--  Posts2Controller.php
 |...     |...      `--  Posts3Controller.php
 |...     |...      `--  Posts4Controller.php 
 |--  backend
 |

and in my register Namespaces:

$loader = new Loader();
        $loader->registerNamespaces(array(
            'Apps\Main\Controllers' => __DIR__ . '/controllers/',
            'Apps\Main\Controllers\API' => __DIR__ . '/controllers/api/',
            'Apps\Main\Models' => __DIR__ . '/models/',
            'Apps\Main\Forms' => __DIR__ . '/forms/',
            'Multiple\Frontend\Libraries' => __DIR__ . '/library/'
        ));
        $loader->register();

and in API1Controller.php file I add this code:


namespace Apps\Main\Controllers\API;

but doesn't work

why ?

sry for bad type english

Try adding an events manager to the loader to see what paths are being tried: https://docs.phalcon.io/en/latest/reference/loader.html#autoloading-events