多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 自动加载 > composer.json ~~~ "autoload": { "psr-4": { "Application\\": "module/Application/src/", "Album\\": "module/Album/src/", "Blog\\": "module/Blog/src/" } } ~~~ 执行 ~~~ composer dump-autoload ~~~ ### 模块管理器 > module/Blog/src/Module.php ~~~ <?php namespace Blog; class Module { public function getConfig() { return include __DIR__ . '/../config/module.config.php'; } } ~~~ **模块配置** > module/Blog/config/module.config.php ~~~ <?php namespace Blog; use Zend\Router\Http\Literal; use Zend\ServiceManager\Factory\InvokableFactory; return [ // This lines opens the configuration for the RouteManager 'router' => [ // Open configuration for all possible routes 'routes' => [ // Define a new route called "blog" 'blog' => [ // Define a "literal" route type: 'type' => Literal::class, // Configure the route itself 'options' => [ // Listen to "/blog" as uri: 'route' => '/blog', // Define default controller and action to be called when // this route is matched 'defaults' => [ 'controller' => Controller\ListController::class, 'action' => 'index', ], ], ], ], ], 'controllers' => [ 'factories' => [ Controller\ListController::class => InvokableFactory::class, ], ], 'view_manager' => [ 'template_path_stack' => [ __DIR__ . '/../view', ], ], ]; ~~~ ### 控制器 > [module/Blog/src/Controller/ListController.php](https://gitee.com/netjoin/zendframework3-demo/blob/master/module/Blog/src/Controller/ListController.php) ~~~ <?php namespace Blog\Controller; use Zend\Mvc\Controller\AbstractActionController; class ListController extends AbstractActionController { } ~~~ **视图** > [module/Blog/view/blog/list/index.phtml](https://gitee.com/netjoin/zendframework3-demo/blob/master/module/Blog/view/blog/list/index.phtml) ~~~ <h1>Blog\ListController::indexAction()</h1> ~~~