* Get Cake's root directory
*/
define('APP_DIR', 'app');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
ここで、定数として設定しています。
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT);
}
/**
* Set the include path or define app and core path
*/
if (function_exists('ini_set')) {
ini_set('include_path',
ini_get('include_path') . PATH_SEPARATOR
. CAKE_CORE_INCLUDE_PATH
. PATH_SEPARATOR . ROOT . DS . APP_DIR . DS
);
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
さらに、.htaccess内
でwebrootへindexを移動させています。RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L]
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
//もしDSの区切り定数が無かった宣言
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(__FILE__))));
}
//もしAPP_DIRが決まってなければ宣言
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(__FILE__))));
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT);
}
//CAKE_CORE_INCLUDE_PATHが決まってなければ宣言
//以下、自己責任で編集との事
if (!defined('WEBROOT_DIR')) {
define('WEBROOT_DIR', basename(dirname(__FILE__)));
}
if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set')
&& ini_set('include_path',
CAKE_CORE_INCLUDE_PATH
. PATH_SEPARATOR . ROOT
. DS
. APP_DIR
. DS
. PATH_SEPARATOR
. ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
//それぞれ宣言でfunction_exists関数でini_setも宣言
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error(
"CakePHP core could not be found.
Check the value of CAKE_CORE_INCLUDE_PATH
in APP/webroot/index.php.
It should point to the directory containing your "
. DS . "cake core directory and your "
. DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
return;
} else {
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch();
}
このini_setでエラーを制御そして "CakePHP core could not be found. ~を出力ですね。
要は定数としてパスが設定してなければ、エラーメッセージを出すという形です。
で、実際のindex.phpgはapp/webrootにあります。
ルート絡みのページはこちらに配置します。