YII 모듈 로 딩 루트 의 실현 방법

원인프로젝트 가 커서 모듈 을 많이 그 었 어 요.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현재 모듈 의 아래 경로 설정
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기