2016年3月5日土曜日

cakephp3 でユーザー定義定数ファイルを作成する -- create a user-defined constants file of cakephp3 --

PHP Ver 5.6.27
CakePHP Ver 3.1.9



1. ユーザー定義定数を記載したファイルを作成する

・ここでは例としてconst.phpというファイルを作成
config/const.phpを作成
--------------------------------------
return [
  'Common' => [
    'Valid_User' => 0
  ]
];
--------------------------------------
配列で定義することに注意


2. ユーザー定義定数ファイルを読み込ませる

・ここでは例としてconst.phpというファイルを読み込ませる
config/app.php もしくは config/bootstrap.phpを編集
--------------------------------------
Configure::load('const', 'default'); ← この行を追記
--------------------------------------


3. ユーザー定義定数ファイルを利用する

--------------------------------------
use Cake\Core\Configure; ← この行を追記

Configure::read('Common.Valid_User');
--------------------------------------


1. create a user-defined constants file

・ example: Create a file called const.php
Create a const.php under config directory
--------------------------------------
return [
  'Common' => [
    'Valid_User' => 0
  ]
];
--------------------------------------
Note that defined by the array


2. To read the user-defined constants file

・ example: Read a file called const.php
edit app.php or bootstrap.php
--------------------------------------
Configure::load('const', 'default'); ← add this line
--------------------------------------


3. To use the user-defined constants

--------------------------------------
use Cake\Core\Configure; ← add this line

Configure::read('Common.Valid_User');
--------------------------------------

0 件のコメント:

コメントを投稿