CakePHP FormHelper の月表示変更

2010年 04月 11日

    CakePHPver1.2.6

    まず、これを
    /cake/lib/view/helper/form.php
    ココに持ってくる!
    /app/view/helper/

    次にmonthファンクションをいじる

    	function month($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
    		if ((empty($selected) || $selected === true) && $value = $this->value($fieldName)) {
    			if (is_array($value)) {
    				extract($value);
    				$selected = $month;
    			} else {
    				if (empty($value)) {
    					if (!$showEmpty) {
    						$selected = 'now';
    					}
    				} else {
    					$selected = $value;
    				}
    			}
    		}
    
    		if (strlen($selected) > 2) {
    			$selected = date('m', strtotime($selected));
    		} elseif ($selected === false) {
    			$selected = null;
    		}
    		$defaults = array('monthNames' => false);  //<=ここのtrueをfalseに変えます。
    		$attributes = array_merge($defaults, (array) $attributes);
    		$monthNames = $attributes['monthNames'];
    		unset($attributes['monthNames']);
    
    		return $this->select(
    			$fieldName . ".month",
    			$this->__generateOptions('month', array('monthNames' => $monthNames)),
    			$selected, $attributes, $showEmpty
    		);
    	}
    

    これで英語表記から数字表記に変わる!
    以上
    ヽ(´ー`)ノ

    ★☆★☆★☆ ナウでヤングなレンタルサーバー!ロリポップ! ☆★☆★☆★
    月額105円~容量最大30GB!WordpressやMovable Typeの簡単インストール付★

    Post a Comment