cakephp3 ディレクトリ階層変更

(composer.pharの場所 www.test.co.jp直下)
sudo php composer.phar create-project –prefer-dist -s dev cakephp/app /var/www/www.test.co.jp/cake/app/mb

mb以下のファイルはすべて削除(bin~webrootのディレクトリのみの状態)

webroot内の以下のディレクトリ、ファイルを「html/m」へ移動
css
img
js
favicon.ico

以下のファイルを「html/m」へコピー
.htaccess
index.php

.htaccess修正
<IfModule mod_rewrite.c>
    RewriteEngine on
    # RewriteRule ^$ webroot/ [L]
    # RewriteRule (.*) webroot/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [L]
</IfModule>

index.php修正
//require ‘webroot’ . DIRECTORY_SEPARATOR . ‘index.php’;
require dirname(dirname(__DIR__)) . ‘/cake/app/mb/webroot/index.php’;

config/bootstrap.php修正
//require ROOT . DS . ‘vendor’ . DS . ‘autoload.php’;
require dirname(dirname(dirname(__DIR__))) . DS . ‘vendor’ . DS . ‘autoload.php’;

config/paths.php修正
//define(‘CAKE_CORE_INCLUDE_PATH’, ROOT . DS . ‘vendor’ . DS . ‘cakephp’ . DS . ‘cakephp’);
define(‘CAKE_CORE_INCLUDE_PATH’, dirname(dirname(dirname(__DIR__))) . DS . ‘vendor’ . DS . ‘cakephp’ . DS . ‘cakephp’);

define(‘CAKE_APP’, ‘mb’);//追加

vendor/composer修正
appディレクトリのsrcの場所を指定している箇所がある。
ここの指定を修正しないと、「[Cake\Routing\Exception\MissingControllerException] Controller class」とか言われる。
composer.phar実行時の引数によって、ファイルや記載方法が違うので、composer内で「src」で検索してヒットした箇所を修正。
例1)
※こちらは、そのままにしておくと、XAMPPで接続した時、Error: [Cake\Routing\Exception\MissingControllerException] Controller class Tests could not be found. となった。
vendor/composer/autoload_psr4.php
‘App\\Test\\’ => array($baseDir . ‘/tests’),
‘App\\’ => array($baseDir . ‘/src’),

‘App\\Test\\’ => array($baseDir . ‘/app/’.CAKE_APP.’/tests’),
‘App\\’ => array($baseDir . ‘/app/’.CAKE_APP.’/src’),

例2)
vendor/composer/autoload_static.php
‘App\\Test\\’ =>
    array (
        0 => __DIR__ . ‘/../..’ . ‘/tests’,
    ),
‘App\\’ =>
    array (
        0 => __DIR__ . ‘/../..’ . ‘/src’,
    ),

‘App\\Test\\’ =>
    array (
        0 => __DIR__ . ‘/../..’ . ‘/app/’.CAKE_APP.’/tests’,
    ),
‘App\\’ =>
    array (
        0 => __DIR__ . ‘/../..’ . ‘/app/’.CAKE_APP.’/src’,
    ),

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です