##Phalcon app\controllers\ 下多目录 该怎么设置?
·public/index.php 注册命名空间
```
$loader->registerNamespaces([
'app\controllers\admin'=>'../app/controllers/admin',
])->register();
$loader->register();
```
·app/config/router.php 添加路由条件
```
$router = $di->getRouter();
$modules = [
'admin' => 'admin',
'api' => 'Api',
];
foreach ($modules as $key => $name) {
$router->add('/' . $key . '/:controller/:action/:params', [
'namespace' => "app\\controllers" . ($name ? "\\$name" : ""),
'controller' => 1,
'action' => 2,
'params' => 3
]);
}
$router->handle();
```
admin/TestController.php
```
命名空间必须与loader.php中的设置相对应
namespace app\controllers\admin
```
网友评论