无为清净楼资源网 Design By www.qnjia.com
起因。因为项目比较大了之后划了很多模块。就使得config下面的路由文件变得很庞大,变得不好维护。这个时候就想如果可以把路由拆分到不同模块去自己管理,就会变得清晰很多。
拆了之后项目配置结构如下
新增了一个modules.php
来管理模块的加载
调整之前 web.php
的模块加载配置如下
'modules' => [ 'setup' => [ 'class' => 'appcomponents\modules\setup\Module', ], 'shareorder' => [ 'class' => 'appcomponents\modules\shareorder\Module', ], ]
调整之后 web.php
模块配置如下
'modules' => require (__DIR__).'/modules.php',
modules.php
里面配置如下
return [ 'setup' => [ 'class' => 'appcomponents\modules\setup\Module', ], 'shareorder' => [ 'class' => 'appcomponents\modules\shareorder\Module', ], ];
然后修改rules.php
$default = [ ]; $modules = require __DIR__.'./modules.php'; $roles = []; foreach ($modules as $module) { $class = new ReflectionClass($module['class']); $filePath = $class->getFileName(); $filePath = str_replace('Module','rules',$filePath); if(file_exists($filePath)) { $role = require $filePath; $roles = array_merge($roles,$role); } } return array_merge($roles,$default);。
利用反射找到每个模块的真实路径,然后加载当前模块下的rules.php
文件
每个模块的目录结构
其中Modules.php
是配置当前模块,加载命名空间等。rules.php
为当前模块的下的路由配置
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
标签:
YII分模块加载路由
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】