YII 모듈 로 딩 루트 의 실현 방법
뜯 은 후에 프로젝트 구성 구 조 는 다음 과 같다.
모듈 의 로드 를 관리 하기 위해
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
현재 모듈 의 아래 경로 설정이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.