LoginSignup
3
2

More than 5 years have passed since last update.

FuelPHPで選択肢を日本語化する

Last updated at Posted at 2014-12-25

Selectタグで使う配列をLangで定義しておくと便利

日本語を定義

  • 'DBに入る値'=>'日本語'
fuel/app/lang/ja/selector.php
<?php
return array(

    'contract_type' => array(
        ''    => '--',
        '1'    => '普通借家',
        '2'    => '定期借家',
        '99'    => 'その他',
    ),

    'has_parking' => array(
        '0'    => 'なし',
        '1'    => 'あり',
    ),

    'layout' => array(
        ''    => '--',
        '1room'   => 'ワンルーム',
        '1k'      => '1K',
        '1dk'     => '1DK',
        '1ldk'    => '1LDK',

フォームで使用

<?php echo Form::select('layout', Input::post('layout', isset($item) ? $item->layout : ''), 
                __('selector.layout'), 
                array('class' => 'form-control')); ?>

表示

<?php echo \Arr::get(__('selector.layout'),$item->layout,''); ?>

関係ないけど

Placeholderも同様に定義しておくと便利

fuel/app/lang/ja/placeholder.php
<?php

return array(

    'model' => array(
        //1 建物
        'building' => array(
            'name'             => '田中荘',
            'name_kana'        => 'タナカソウ',
            'zip_code'         => '000-0000',
            'city'             => '渋谷区',
            'address'          => '渋谷 1-2-3',
            'city_kana'        => 'シブヤク',
            'address_kana'     => 'シブヤ',
            <?php echo Form::input('name', Input::post('name', isset($item) ? $item->name : ''), 
                array('class' => 'form-control', 'placeholder'=>__('placeholder.model.building.name')));  
            ?>
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