これはあなたが探しているものよりも多いかもしれませんが、これはサイト全体の構成を1つのファイルに入れて、簡単に利用できるようにする方法です。
configフォルダーにファイルがあります:my_custom_settings.php
そのファイルで、次のような構成値を設定します。
$config['TEMPLATE_DIR'] = 'assets/front' ;
$config['site_slogan'] = 'Laravel? Never heard of it' ;
My_custom_settings.phpという名前の別のファイルを作成します
そのファイルを次の場所に配置します:application / library / My_custom_settings.phpそのファイルには次のものが含まれます:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class My_custom_settings
{
function __construct($config = array() )
{
foreach ($config as $key => $value) {
$data[$key] = $value;
}
// makes it possible for CI to use the load method
$CI =& get_instance();
// load the config variables
$CI->load->vars($data);
}
} // end my custom settings
今あなたのコントローラーコンストラクターに
public function __construct() {
parent::__construct();
// Load configs for controller and view
$this->load->library( 'my_custom_settings' );
$this->config->load( 'my_custom_settings' );
} // end construct
ここで、クールな部分について説明します。その構成ファイルに入力したものはすべて、コントローラーとビューで使用できるようになります。(configをモデルコンストラクターにロードすることもできます)。
コントローラまたはモデルでは、次のように$this->configで値を取得します。
$this->config->item( 'site_slogan' )
少し厄介ですが、ビューの場合、ここに報酬があります。必要なのは構成名だけです。
echo $TEMPLATE_DIR . '/somefile' ;