어플리케이션 관리

기본적으로 CodeIgniter를 사용하여 하나의 어플리케이션만 관리한다면 app 디렉토리에 빌드됩니다. 그러나 단일 CodeIgniter를 공유하는 여러 어플리케이션 세트를 보유하거나, 어플리케이션 디렉토리의 이름을 바꾸거나 재배치할 수도 있습니다.

Important

CodeIgniter v4.1.9 또는 이전 버전을 설치했다면 /composer.json파일의 autoload.psr-4App\\Config\\ 네임스페이스가 있는 경우 다음과 같이 이 줄을 제거하고 composer dump-autoload를 실행해야 합니다.

{
    ...
    "autoload": {
        "psr-4": {
            "App\\": "app",             <-- Remove this line
            "Config\\": "app/Config"    <-- Remove this line
        }
    },
    ...
}

어플리케이션 디렉토리 이름 바꾸기 또는 재배치

어플리케이션 디렉토리의 이름을 바꾸거나 프로젝트 루트를 서버의 다른 위치로 옮기려면 app/Config/Paths.php 파일의 $appDirectory 변수에 전체 서버 경로를 설정하십시오.(44번째 행)

<?php

namespace Config;

class Paths
{
    // ...

    public $appDirectory = '/path/to/your/app';

    // ...
}

Paths 구성 파일을 찾을 수 있도록 프로젝트 루트의 두 개의 파일을 수정해야 합니다.

  • /spark 커맨드 라인(command line) 앱 실행에 사용됩니다.

    <?php
    
    require FCPATH . '../app/Config/Paths.php';
    // ^^^ Change this line if you move your application folder
    
  • /public/index.php webapp의 프론트 컨트롤러입니다.

    <?php
    
    require FCPATH . '../app/Config/Paths.php';
    // ^^^ Change this line if you move your application folder
    

하나의 설치된 CodeIgniter로 여러 어플리케이션 실행하기

이미 설치된 CodeIgniter 프레임워크를 공유하여 여러 다른 어플리케이션을 사용하려면 어플리케이션 디렉토리 내부에 있는 모든 디렉토리를 자체(또는 서브) 디렉토리에 두십시오.

예를 들어 foobar라는 두 개의 어플리케이션을 만들고 싶다고 가정해 봅시다. 다음과 같이 어플리케이션 프로젝트 디렉토리를 구성할 수 있습니다.

foo/
    app/
    public/
    tests/
    writable/
    env
    phpunit.xml.dist
    spark
bar/
    app/
    public/
    tests/
    writable/
    env
    phpunit.xml.dist
    spark
vendor/
    autoload.php
    codeigniter4/framework/
composer.json
composer.lock

Note

Zip 파일에서 CodeIgniter를 설치하는 경우 디렉터리 구조는 다음과 같습니다.

foo/
bar/
codeigniter4/system/

여기에는 foobar**라는 두 개의 앱이 있으며 둘 다 표준 애플리케이션 디렉토리와 **public 폴더가 있고 공통 codeigniter4/framework를 공유합니다.

각각의 app/Config/Paths.php에 있는 $systemDirectory 변수는 공유된 공통 codeigniter4/framework 폴더를 참조하도록 설정됩니다.

<?php

namespace Config;

class Paths
{
    // ...

    public $systemDirectory = __DIR__ . '/../../../vendor/codeigniter4/framework/system';

    // ...
}

그리고 각각의 app/Config/Constants.php에서 COMPOSER_PATH 상수를 수정합니다.

<?php

defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . '../vendor/autoload.php');

애플리케이션 디렉토리를 변경할 때만 어플리케이션 디렉토리 이름 바꾸기 또는 재배치를 참조하고 index.phpspark의 경로를 수정합니다.