3
2

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で配列を設定ファイルから呼び出す

Last updated at Posted at 2018-06-14

固定された内容の配列を、コントローラーやモデルのどこでも呼び出せる様に、config配下に設定する。たとえば、住所入力時の都道府県のリストなど。

CIのversion

CI_VERSION = '3.1.8';

config配下に都道府県の配列のファイルを置く。

application/config/prefectures.php


$config['prefectures'] = array(
    '1'=>'東京',
    '2'=>'神奈川'
);

autoloadを設定

application/config/autoload.php


$autoload['config'] = array('prefectures');

配列の呼び出し

どこのコントローラー、モデルからでも、以下で都道県の配列を取得できる。

$this->config->item('prefectures');
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?