8
4

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.

cakephp3 コア定義定数まとめ

8
Last updated at Posted at 2018-01-10

パス定数の基本定義

定数 説明
ROOT ルートディレクトリーへのパス
APP_DIR アプリケーションのディレクトリ名
CAKE_CORE_INCLUDE_PATH Cakeライブラリへのパス
WEBROOT_DIR webrootディレクトリ名
WWW_ROOT webrootへのフルパス
DS PHPのDIRECTORY_SEPARATORの省略語。
つまりLinux の場合は / Windows の場合は \ を指します。

基本定義から組み合わせた定数

定数 説明
CORE_PATH CAKE_CORE_INCLUDE_PATH + ディレクトリセパレータ
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
CAKE CORE_PATH + 'src' + ディレクトリセパレータ
define('CAKE', CORE_PATH . 'src' . DS);
APP ROOT + APP_DIR + ディレクトリセパレータ
define('APP', ROOT . DS . APP_DIR . DS);
APPLIBS define('APPLIBS', APP . 'Lib' . DS);
TESTS Testディレクトリ
define('TESTS', ROOT . DS . 'tests' . DS);
TMP TMPディレクトリ(キャッシュやCakeログのベース)
define('TMP', ROOT . DS . 'tmp' . DS);
CACHE キャッシュが保存されるディレクトリ
define('CACHE', TMP . 'cache' . DS);
LOGS Cakeログが保存されるディレクトリ
define('LOGS', ROOT . DS . 'logs' . DS);

CSS JS 画像ファイルのパス

app.phpでの定義

'App' => [
    'namespace' => 'App',
    'encoding' => env('APP_ENCODING', 'UTF-8'),
    'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US'),
    'base' => false,
    'dir' => 'src',
    'webroot' => 'webroot',
    'wwwRoot' => WWW_ROOT,
    // 'baseUrl' => env('SCRIPT_NAME'),
    'fullBaseUrl' => false,
    'imageBaseUrl' => 'img/',
    'cssBaseUrl' => 'css/',
    'jsBaseUrl' => 'js/',
    'paths' => [
        'plugins' => [ROOT . DS . 'plugins' . DS],
        'templates' => [APP . 'Template' . DS],
        'locales' => [APP . 'Locale' . DS],
    ],
],

css/であれば、
App.cssBaseUrlとして呼び出しが可能。

定義を変更する場合

tmpやcacheディレクトリを別に設定する場合下記のように変更する

if (!defined('TMP')) {
    define( 'TMP', "TMPディレクトリへのパス");
}

Reference

cakephp3だと、下記ファイルにdefineされています。
app/config/paths.php

8
4
0

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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?