3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CodeIgniter 3. Composer のときのディレクトリ構成がちょっといや

Last updated at Posted at 2015-09-29

1. Composerでインストールしてみる

codeigniter/frameworkのとおりにやると、

$ composer require codeigniter/framework
/
├── composer.json
├── composer.lock
└── vendor
    ├── autoload.php
    ├── codeigniter
    └── composer
composer.json
{
    "require": {
        "codeigniter/framework": "^3.0"
    }
}

これだと、index.phpが vendor/codeigniter/framework/ にいて、ここをルートにする仕様なのかな?
create-project も試してみる。

$ composer create-project codeigniter/framework [dir_name]
/
└── dir_name
    ├── application
    ├── composer.json
    ├── composer.lock
    ├── contributing.md
    ├── index.php
    ├── license.txt
    ├── readme.rst
    ├── system
    ├── user_guide
    └── vendor

これならよさそうかと思ったら、フレームワークのコアがvendorの外のsystemに入っててなんかおかしい。github のディレクトリ構成が Composer向きじゃないのかな。
Composerではなくて、Sparksなのでしょう。

2. require を使う方向でファイル構成変更する

まず、composer.json をそれっぽく書き足す。

composer.json
{
    "require": {
        "php": ">=5.2.4",
        "codeigniter/framework": "^3.0"
    },
    "require-dev": {
        "mikey179/vfsStream": "1.1.*"
    }
}

index.phpと appricationディレクトリを頭ににコピーする。.htaccess も置いておく。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
/
├── .htaccess
├── application
├── composer.json
├── composer.lock
├── index.php
└── vendor
    ├── autoload.php
    ├── codeigniter
    ├── composer
    └── mikey179

index.php を直す。

index.php
$system_path = 'vendor/codeigniter/framework/system';

apprication/config/config.php を直す。

config.php
//$config['composer_autoload'] = FALSE;
$config['composer_autoload'] = TRUE;
$config['composer_autoload'] = FCPATH . '/vendor/autoload.php';

create-project でこんな感じになってくれるといいなと思う。composer update もできるし、他のフレームワークはこういう方向よね?

3
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?